'(Python)element at the equal interval from the end
How to get [1,4,7] from the my_list [1,2,3,4,5,6,7,8,9], which is the list of elements at the equal interval(in this case, 3) "from the end" of the my_list?
my_list =[1,2,3,4,5,6,7,8,9]
# how to get [1,4,7] from the list above?
Solution 1:[1]
if [1,4,7]
is supposed to be the result this snipped of code should do the job
my_list=[1,2,3,4,5,6,7,8,9]
print(list(reversed(my_list[-3::-3])))
result
[1, 4, 7]
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 | Xavier Combelle |