I have a list of tuples that looks like this:
[(\'a\', \'b\'), (\'c\', \'d\'), ((\'e\', \'f\'), (\'h\', \'i\'))]
I want to turn it into thi
A one-line solution would be using itertools.chain:
itertools.chain
>>> l = [('a', 'b'), ('c', 'd'), (('e', 'f'), ('h', 'i'))] >>> from itertools import chain >>> [*chain.from_iterable(x if isinstance(x[0], tuple) else [x] for x in l)] [('a', 'b'), ('c', 'd'), ('e', 'f'), ('h', 'i')]