Created
June 16, 2022 04:16
-
-
Save plavjanik/aa284cb64dcc3631d256e36d2d01c16f to your computer and use it in GitHub Desktop.
Looping over a collection and indices
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)): | |
| 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