Last active
January 28, 2018 21:12
-
-
Save caffeine-potent/6a3324436e722c4571e51a5c5b60d890 to your computer and use it in GitHub Desktop.
List comprehension with depth = 2
This file contains 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
# | |
# Solution to a question posed in https://www.reddit.com/r/learnpython/comments/72ll3i/list_comprehension_help/ | |
# | |
# def gen_function_that_can_be_one_lined(my_list): | |
# for i, x in enumerate(my_list): | |
# for y in x: | |
# yield ( i, y) | |
# | |
#List | |
example_1 = [( i, y) for i, x in enumerate(my_list) for y in x] | |
#Generator | |
example_2 = (( i, y) for i, x in enumerate(my_list) for y in x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment