I am creating a number of slices [-WINDOW-i:-i]
of a list, where i
ranges between 32
and 0
:
vals = []
for i in range(32, -1, -1):
vals.append(other_list[-WINDOW-i:-i])
When i == 0
, this returns a slice of length 0:
other_list[-WINDOW-0:0]
I don't want to have to do this to solve it:
vals = []
for i in range(32, -1, -1):
if i == 0:
vals.append(other_list[-WINDOW:])
else:
vals.append(other_list[-WINDOW-i:-i])
… because if I have many lists to append to vals
, it gets messy.
Is there a clean way to do this?