Created
August 23, 2020 11:15
-
-
Save yangyushi/10e925c7e47eb4a401bb89c538081270 to your computer and use it in GitHub Desktop.
if you try to use nested for loop in a list comprehension in python, wat
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
A = [1, 2, 3, 4] | |
B = ['a', 'b', 'c'] | |
# saw this version on a Coursera Course | |
# If you actually use this crappy style, wat | |
print([a for b in B for a in A]) | |
# Equivilant | |
result = [] | |
for b in B: | |
for a in A: | |
result.append(a) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment