I'm trying to get all possible combinations for each list in a nested list. I've tried the following code below, but it is printing an empty list
import json
from pprint import pprint
import itertools
variant = [[{"Typ": "Bridge"}, {"Typ": "Media"}, {"Typ": "Tower"}], [{"Kabeleinf\u00fchrung": "Kabelverschraubung Kunststoff \u00d8 79 mm"}, {"Kabeleinf\u00fchrung": "Power T\u00fclle Twist \u00d8 80 mm"}, {"Kabeleinf\u00fchrung": "Power Grommet Twist USB Daten / Ladung \u00d8 80 mm"}, {"Kabeleinf\u00fchrung": "Power T\u00fclle GST 18 \u00d8 80 mm"}], [{"Whiteboard": "Ohne"}, {"Whiteboard": "Mitt"}], [{"::gote::gote::@GGOTE_WhiteboardShelf": "Ohne"}, {"::gote::gote::@GGOTE_WhiteboardShelf": "Mitt"}], [{"TV-Halterung": "Ohne"}, {"TV-Halterung": "Mitt"}], [], [{"Stoff": "Event screen + (Preisklasse 1)"}, {"Stoff": "Cara (Preisklasse 1)"}, {"Stoff": "Carlow (Preisklasse 1)"}, {"Stoff": "Pearl (Preisklasse 1)"}, {"Stoff": "Omega (Preisklasse 1)"}, {"Stoff": "Xpress (Preisklasse 1)"}, {"Stoff": "Hush (Preisklasse 1)"}, {"Stoff": "Mica (Preisklasse 1)"}, {"Stoff": "Slope (Preisklasse 1)"}, {"Stoff": "Noble Lux (Preisklasse 2)"}, {"Stoff": "Houston Reflect (Preisklasse 2)"}, {"Stoff": "Kunstleder (Preisklasse 2)"}, {"Stoff": "Lido (Preisklasse 2)"}, {"Stoff": "Twist (Preisklasse 2)"}, {"Stoff": "Rivet (preisklasse 2)"}, {"Stoff": "Blazer (Preisklasse 3)"}, {"Stoff": "Blazer Lite (pris gruppe 3)"}, {"Stoff": "Synergy (Preisklasse 3)"}, {"Stoff": "Bond (Preisklasse 3)"}, {"Stoff": "Hint (Preisklasse 3)"}, {"Stoff": "Remix 3 (preisklasse 4)"}, {"Stoff": "Step (Preisklasse 4)"}], [{"Stofffarbe": "01 (60000 BY GABRIEL)"}, {"Stofffarbe": "02 (61008 BY GABRIEL)"}, {"Stofffarbe": "03 (61011 BY GABRIEL)"}, {"Stofffarbe": "04 (60004 BY GABRIEL)"}, {"Stofffarbe": "05 (60002 BY GABRIEL)"}, {"Stofffarbe": "06 (60021 BY GABRIEL)"}, {"Stofffarbe": "07 (60999 BY GABRIEL)"}, {"Stofffarbe": "08 (67015 BY GABRIEL)"}, {"Stofffarbe": "09 (67017 BY GABRIEL)"}], [{"Type": "110010"}]]
print(list(itertools.product(*variant)))
this is my current code.
[('Typ--Bridge','Kabeleinführung--Kabelverschraubung Kunststoff Ø 79 mm', 'Whiteboard--Ohne'),('Typ--Bridge','Kabeleinführung--Kabelverschraubung Kunststoff Ø 79 m', 'Whiteboard--Mitt'),('Typ--Bridge', 'Kabeleinführung--Power Tülle Twist Ø 80 mm', 'Whiteboard--Ohne'), ('Typ--Bridge', 'Kabeleinführung--Power Tülle Twist Ø 80 mm',
'Whiteboard--Mitt'),
this is what I want the output to look like. It seems the problem is in the unpacking of the nested lists, which when I run separately isn't separated by commas, but I just can't figure out what is wrong exactly.
Check the lengths of all the elements in variant
. You'll see that one of them has length zero.
In [13]: [len(i) for i in variant]
Out[13]: [3, 4, 2, 2, 2, 0, 22, 9, 1]
This empty list should be removed from your input. itertools.product
takes one element from every one of its arguments in each of its output values, so any empty lists will cause it to return no results.