To get all the elements of x between second and twelfth elements having even indexes, you can use Python list slicing as follows:
main.py10 chars2 lines
Here, x[2:13:2]
returns a new list that contains the elements of the x
list starting from the second element up to but not including the thirteenth element, with a step of 2, which means that it only takes elements with even indexes.
For example, if x
is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
, then x[2:13:2]
will return [2, 4, 6, 8, 10, 12]
.
So the final answer to this problem is:
main.py10 chars2 lines
gistlibby LogSnag