Skip to content

Instantly share code, notes, and snippets.

@yangyushi
Created August 23, 2020 11:15
Show Gist options
  • Save yangyushi/10e925c7e47eb4a401bb89c538081270 to your computer and use it in GitHub Desktop.
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
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