Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save plavjanik/aa284cb64dcc3631d256e36d2d01c16f to your computer and use it in GitHub Desktop.

Select an option

Save plavjanik/aa284cb64dcc3631d256e36d2d01c16f to your computer and use it in GitHub Desktop.
Looping over a collection and indices
colors = ["cyan", "magenta", "yellow", "black"]
# ❌
for i in range(len(colors)):
print(f"{i} --> {colors[i]}")
# ✔️
for i, color in enumerate(colors):
print(f"{i} --> {color}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment