Suppose I have a set of column definitions:
Col1: value11 value12 value13
Col2: value21 value22
Col3: value31 value32 value33
...
Given some subset of columns — 2 or more — I want to find all possible values for those columns. Suppose I choose columns 1 and 2, above:
(value11 value21)
(value11 value22)
(value12 value21)
(value12 value22)
(value13 value21)
(value13 value22)
If I’d chosen 2:3:
(value21 value31)
(value21 value32)
(value21 value33)
(value22 value31)
(value22 value32)
(value22 value33)
If I’d chosen all three:
(value11 value21 value31)
(value11 value21 value32)
...
I’m implementing this in python, and I’d like a fast algorithm to do this. My input is a list of tuples: (columnName, columnValueList)
Any suggestions?
The best way to get this is going to be using itertools.product(). For example:
This function accepts multiple arguments (i.e. multiple columns).
For more help on iterools.product() see this.