Skip to content

Instantly share code, notes, and snippets.

@plavjanik
Created June 16, 2022 04:07
Show Gist options
  • Select an option

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

Select an option

Save plavjanik/7aeaa60cdc6d0c4b30d2f0de638c84e7 to your computer and use it in GitHub Desktop.
Looping backwards
colors = ["cyan", "magenta", "yellow", "black"]
# ❌
for i in range(len(colors) - 1, -1, -1):
print(colors[i])
# ✔️
for color in reversed(colors):
print(color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment