Skip to content

Instantly share code, notes, and snippets.

@nunenuh
Created May 5, 2019 14:02
Show Gist options
  • Save nunenuh/59cd3e64c0d96590f18c48fdd8dec675 to your computer and use it in GitHub Desktop.
Save nunenuh/59cd3e64c0d96590f18c48fdd8dec675 to your computer and use it in GitHub Desktop.
Idiomatic Python
# Looping Over Two Collection
names = ["raymond", "rachel","matthew"]
colors = ["red", "green", "blue"]
# bad
n = min(len(names), len(colors))
for i in range(n):
print(names[i], '--', colors[i])
# good
for name, color in zip(names, colors):
print(name, '--', color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment