How would one create a sublist by pulling every other element within another list.
I have a list that looks like this:
a = ['12','23','34']
I then use the enumerate function to assign a value to each element within the list.
b = list(enumerate(a, start=1))
So the result of b (key, values):
>>> b
>>> [(1,'12'),(2,'23'),(3, '34')]
Now, I've been looking around the internet (mainly using Google) and I've been reading documentation but I can't find a direct answer. How can I pull every odd key into another list?
The results that I want:
[(1,'12'),(3,'34')]
Here's what I've been trying:
1.)
for i in b:
c = b[i%2 == 1]
2.)
for i in b:
if (i%2):
c = i
If you have any suggestions for improvement, please let me know.