Created
June 16, 2022 06:31
-
-
Save plavjanik/e9a1f3a222aa9c2c77f21aa05ed3d819 to your computer and use it in GitHub Desktop.
Looping over two collections
This file contains 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
names = ["Pierre", "Per", "Peter"] | |
colors = ["cyan", "magenta", "yellow", "black"] | |
# ❌ | |
n = min(len(names), len(colors)) | |
for i in range(n): | |
print(f"{names[i]} --> {colors[i]}") | |
# ✔️ | |
for name, color in zip(names, colors): | |
print(f"{name} --> {color}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment