How can I convert
([1,2,3],[4,5])
to
(1,2,3,4,5)
in Python?
I just want to convert the lists in the tuple to a single tuple, it means to remove the list.
How can I convert
([1,2,3],[4,5])
to
(1,2,3,4,5)
in Python?
I just want to convert the lists in the tuple to a single tuple, it means to remove the list.
tpl = ([1,2,3],[4,5])
print(tuple(sum(tpl, [])))
Prints:
(1, 2, 3, 4, 5)
OR:
Using itertools.chain
:
from itertools import chain
print(tuple(chain.from_iterable(tpl)))
OR:
Using comprehensions:
print(tuple(i for lst in tpl for i in lst))