Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanMillerC/ab8fb71a7b61d12c4e5c643eb4932dab to your computer and use it in GitHub Desktop.
Save RyanMillerC/ab8fb71a7b61d12c4e5c643eb4932dab to your computer and use it in GitHub Desktop.
Today I learned a better way to loop through parallel lists in Python
L = ['value', 'value2', 'value3']
L2 = ['value', 'value2', 'value3']
# Old-Old way
for index in range(len(L)):
item = L[index]
item2 = L2[index]
print(item, item2)
# Old way
for index, item in enumerate(L):
item2 = L2[index]
print(item, item2)
# New way
for item, item2 in zip(L, L2):
print(item, item2)
@RyanMillerC
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment