Created
January 26, 2020 21:44
-
-
Save nickyfoto/04dd923ab5342c97242d86cfdffc01df to your computer and use it in GitHub Desktop.
one line double for loop in python
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
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