'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, i.e. [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.

hy


Solution 1:[1]

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:].

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kodiologist