Skip to content

Instantly share code, notes, and snippets.

@patwooky
Created December 27, 2016 04:28
Show Gist options
  • Save patwooky/35ef38b69897785f28b6dcdafb958801 to your computer and use it in GitHub Desktop.
Save patwooky/35ef38b69897785f28b6dcdafb958801 to your computer and use it in GitHub Desktop.
Testing out looping over a list with enumerate in Python
myList = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
for idx, y in enumerate(myList):
print idx, y, myList[idx+1] if idx < len(myList)-1 else y
# output
'''
0 a b
1 b c
2 c d
3 d e
4 e f
5 f g
6 g h
7 h i
8 i j
9 j k
10 k k
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment