Skip to content

Instantly share code, notes, and snippets.

@nunenuh
Last active May 5, 2019 14:06
Show Gist options
  • Save nunenuh/632b73ca249d4300d82272845ff606d3 to your computer and use it in GitHub Desktop.
Save nunenuh/632b73ca249d4300d82272845ff606d3 to your computer and use it in GitHub Desktop.
Idiomatic Python
# Looping Over Collection Backward
colors = ["red", "green", "blue"]
# bad
for i in range(len(colors)-1, -1, -1):
print(colors[i])
# good
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