简体   繁体   English

从负值 integer 剪切到 Hy 列表中的最后一项

[英]Cut from negative integer to last item in list in Hy

If (list (range 10)) is [0... 9] , and (cut (list (range 10)) -5 -1) is [5, 6, 7, 8] , then how do I include the last item in the list as well, ie [5, 6, 7, 8, 9] ?如果(list (range 10))[0... 9] ,并且(cut (list (range 10)) -5 -1)[5, 6, 7, 8] ,那么我如何包括最后一个列表中的项目,即[5, 6, 7, 8, 9] I've tried (cut (list (range 10)) -5 0) and (cut (list (range 10)) -5 1) , but both give me empty lists.我试过(cut (list (range 10)) -5 0)(cut (list (range 10)) -5 1) ,但都给了我空列表。

You need to use None as the stop argument, as in (cut (list (range 10)) -5 None) .您需要使用None作为停止参数,如(cut (list (range 10)) -5 None) The difference between (cut x -5) and (cut x -5 None) is the same as between x[slice(-5)] and x[slice(-5, None)] in Python, or equivalently x[:-5] and x[-5:] . (cut x -5)(cut x -5 None)之间的区别与 Python 中x[slice(-5)]x[slice(-5, None)]之间的区别相同,或者等效于x[:-5]x[-5:]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM