How to get all numbers from list which are located at multiple of 3 index

Viewed 424

How to get all numbers from list which are located at multiple of 3 index for example

li=['ab','ha','kj','kr','op','io']

i need

['kj','io']
2 Answers

Use slicing on list where [2::3] means start from 2nd index(indices start from 0 in python) and get every 3rd element

print(li[2::3])

Output:

['kj','io']
for index,i in enumerate(li):
    index = index+1
    if index % 3 == 0: print(i)
Related