I have a list in python, eg. [1,2,3,4,5,6,7,8,9,10,11,12]
I want to make a new list with only the 4. element from the right? .. how to do that, eg. with a one liner.
eq. to .. [4,8,12]
I have a list in python, eg. [1,2,3,4,5,6,7,8,9,10,11,12]
I want to make a new list with only the 4. element from the right? .. how to do that, eg. with a one liner.
eq. to .. [4,8,12]
You can do it simply like so in one line: (where a is your list)
print(a[-1::-4][::-1])
foo = [1,2,3,4,5,6,7,8,9,10,11,12]
print(foo[-1::-4])
output
[12, 8, 4]
reverse it, if the order is important