Mar-18-2018, 05:13 AM
i'm looking over the various functions in itertools but i'm not finding what i need.
my use case is to take a list of lists of strings and iterate over the 2nd level to produce a list of the combination of strings. the incoming list might be:
my use case is to take a list of lists of strings and iterate over the 2nd level to produce a list of the combination of strings. the incoming list might be:
[ ['foo','bar'], ['+','-'], ['corn','wheat','rice'] ]the first 3 and last 3 iterations (in a list) would be:
[ ['foo','+','corn'], ['bar','+','corn'], ['foo','-','corn'], ... ['bar','+','rice'], ['foo','-','rice'], ['bar','-','rice'], ]the whole big list of 12 (in this example) lists is what would be returned. the generator version of this would do a yield of each iteration for a total of 12 yields. better code would be agnostic about what kind of data object or reference is used in place of the strings. i was trying to write this myself. maybe i should go back to that.