Skip to content

Instantly share code, notes, and snippets.

@Yunkou
Last active August 30, 2017 17:44
Show Gist options
  • Save Yunkou/fd447bcc40b7e7fe25065b8fd59a4dde to your computer and use it in GitHub Desktop.
Save Yunkou/fd447bcc40b7e7fe25065b8fd59a4dde to your computer and use it in GitHub Desktop.
Using enumerate()
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