Last active
August 30, 2017 17:44
-
-
Save Yunkou/fd447bcc40b7e7fe25065b8fd59a4dde to your computer and use it in GitHub Desktop.
Using enumerate()
This file contains hidden or 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
cities = ['Marseille', 'Amsterdam', 'New York', 'London'] | |
# The bad way | |
i = 0 | |
for city in cities: | |
print(i, city) | |
i += 1 | |
# The good way | |
for i, city in enumerate(cities): | |
print(i, city) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment