Skip to content

Instantly share code, notes, and snippets.

@nickyfoto
Created January 26, 2020 21:44
Show Gist options
  • Save nickyfoto/04dd923ab5342c97242d86cfdffc01df to your computer and use it in GitHub Desktop.
Save nickyfoto/04dd923ab5342c97242d86cfdffc01df to your computer and use it in GitHub Desktop.
one line double for loop in python
r = []
for i in range(1, 6):
for j in range(7, 9):
r.append((i, j))
print(r)
print(list((i, j) for i in range(1, 6) for j in range(7,9)))
# [(1, 7), (1, 8), (2, 7), (2, 8), (3, 7), (3, 8), (4, 7), (4, 8), (5, 7), (5, 8)]
# [(1, 7), (1, 8), (2, 7), (2, 8), (3, 7), (3, 8), (4, 7), (4, 8), (5, 7), (5, 8)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment