Last active
May 5, 2019 14:06
-
-
Save nunenuh/632b73ca249d4300d82272845ff606d3 to your computer and use it in GitHub Desktop.
Idiomatic Python
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
# 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