Python Cartesian Product

Possible duplicate:
Get the Cartesian product of a series of lists in Python

I'm trying to understand some kind of logic with which I just canโ€™t wrap my head around it. Let's say I have the following data structure:

letters = ( ('b','c'), ('a','e','ee'), ('d','f'), ('e','y'), ) 

How would I iterate over this to get all possible string combinations:

 bade cade bede cede beede ceede bafe cafe befe cefe beefe ceefe bady cady bedy cedy beedy ceedy bafy cafy befy cefy beefy ceefy 
+4
source share
1 answer

I would use itertools.product() :

 for l in itertools.product(*letters): print ''.join(l) 
+6
source

Source: https://habr.com/ru/post/1394243/


All Articles