Just to show another option ... I hope I understood your question correctly ... slicing will give you exactly those list items that you want, without having to cycle through each item or store any enumerations or counters. See Python snippet notation notation .
If you want to start with the 1st element and get every 10th element from this point:
# 1st element, 11th element, 21st element, etc. (index 0, index 10, index 20, etc.) for e in myList[::10]: <do something>
If you want to start with the 10th element and get every 10th element from this point:
# 10th element, 20th element, 30th element, etc. (index 9, index 19, index 29, etc.) for e in myList[9::10]: <do something>
An example of the second option (Python 2):
myList = range(1, 101) # list(range(1, 101)) for Python 3 if you need a list for e in myList[9::10]: print e # print(e) for Python 3
Print
10 20 30 ...etc... 100
mdscruggs
source share