I’ve generated the cartesian product of three dicts thus:
import itertools
combined = list(itertools.product(foo, bar, baz))
So my list now looks like:
[(('text a', 'value a'), ('text b', 'value b'), ('text c', 'value c')), … ]
What I want to do is unpack this list such that I end up with a list of lists containing the flattened nested tuples’ text and values:
[['text a text b text c', 'value a value b value c'], … ]
Is there an efficient general method for doing this?
Follow-up (having seen Dan D.’s answer):
What if my tuples looked like
(('text a', float a), ('text b', float b), ('text c', float c ))
and I wanted to add the floats instead of concatenating the values?
You don’t have to cram everything on one line: