Created
July 30, 2018 13:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More info here: How to iterate through two lists in parallel?