-3

I have a simple question. For example, how can I get the odd numbers in a= ['p','y','t','h','o','n'] array. output to me: It should be ['y','h','n']. Thank you.

Eren k
  • 1
  • 1

2 Answers2

1

you can use slicing :

output = a[1::2]
eshirvana
  • 23,227
  • 3
  • 22
  • 38
0

a = ['p','y','t','h','o','n']

only consider a character where the index is odd

b = [item for idx, item in enumerate(a) if idx % 2 != 0]

print(b) // ['y', 'h', 'n']