python multilevel list comprehension 1

python multilevel list comprehension

>>> [y for x in non_flat for y in x]
[1, 2, 3, 4, 5, 6, 7, 8]

Here is what the above code is Doing:
1. The first line is a list comprehension. It’s creating a list of lists.
2. The second line is a list comprehension. It’s creating a list of integers.
3. The third line is a list comprehension. It’s creating a list of integers.

Similar Posts