Say i have this list:
CP = [1,0,1,0]
How can i print only 0's in the list via indices i.e CP[i].
Required output:
0
0
Any help would be highly appreciated!
Say i have this list:
CP = [1,0,1,0]
How can i print only 0's in the list via indices i.e CP[i].
Required output:
0
0
Any help would be highly appreciated!
This feels like a homework problem, and I assume you actually want odd indices instead of even indices.
Here's a possible solution:
# get a range of all odd numbers between 1 and length of list
# with a step size of 2
for i in range(1, len(CP), 2):
print(CP[i])
The one liner --
print ('\n'.join([str(CP[i]) for i in range(1, len(CP), 2)]))