What the beat way to convert:
[(1, 2), (3, 4)] => [1, 2, 3, 4]
I tried
[i for i in row for row in [(1, 2), (3, 4)]]
but it's not work.
What the beat way to convert:
[(1, 2), (3, 4)] => [1, 2, 3, 4]
I tried
[i for i in row for row in [(1, 2), (3, 4)]]
but it's not work.
You can do this also with chain from itertools
from itertools import chain
a = [(1, 2), (3, 4)]
print(list(chain.from_iterable(a)))
>>>>[1, 2, 3, 4]
A list comprehension is the best way to do this
>>> L = [(1, 2), (3, 4)]
>>> [j for i in L for j in i]
[1, 2, 3, 4]
Note that the "outer loop" variable needs to come first
>>> [i for row in [(1, 2), (3, 4)] for i in row]
[1, 2, 3, 4]
>>>
[i for row in [(1, 2), (3, 4)] for i in row]
^^^^^^^^^^^^^^^^^^^^^^^^^^^ # you need define 'row' before define 'i'