Created
June 16, 2022 04:07
-
-
Save plavjanik/7aeaa60cdc6d0c4b30d2f0de638c84e7 to your computer and use it in GitHub Desktop.
Looping backwards
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
| 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