Skip to content Skip to sidebar Skip to footer

Zip Nested List With List In Python

Python newbie here. I have four lists, three of which are nested lists and one that isn't. I'm searching for a way to zip the nested lists with the list such that the zip function

Solution 1:

The idea is to zip() the main list with the already zipped a, b and c lists and make a nested list comprehension:

>>> [[[item == x for item in l] for l in lists] 
     for x, lists in zip(main, zip(a, b, c))]
[[[True, False, False], [False, True, False], [False, False, False]], 
 [[False, False, False], [True, False, False], [False, False, False]]]

Post a Comment for "Zip Nested List With List In Python"