I'm trying to iterate over a list using enumerator in Python, but I want to display only those element that are at odd index of the list. Please note that I do not wish to use the standard step of dividing and checking remainder by 2
Asked
Active
Viewed 85 times
-5
-
Have you tried anything? – Michael Bianconi Aug 07 '19 at 15:35
-
`for i, item in enumerate(list_name[1::2]):...` – בנימין כהן Aug 07 '19 at 15:36
-
Possible duplicate of [Skipping every other element after the first](https://stackoverflow.com/questions/8865878/skipping-every-other-element-after-the-first) – Sayse Aug 07 '19 at 15:37
2 Answers
0
a = range(1,10)
for x, y in enumerate(a):
if not (x % 2):
print(y)
edit: downvotes? that's not very nice, y'all

keen
- 19
- 4
-
"I do not wish to use the standard step of dividing and checking remainder by 2" – Sayse Aug 07 '19 at 15:39
-
he could keep an idx if he wanted and even/odd it, but whatever, i'm pretty sure with the question level, having modulo do the work for him is acceptable – keen Aug 07 '19 at 15:41
-