简体   繁体   中英

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] ? I've tried (cut (list (range 10)) -5 0) and (cut (list (range 10)) -5 1) , but both give me empty lists.

You need to use None as the stop argument, as in (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:] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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