I have a list M below which came from an external file (This is a large list in reality, len(M)>10000).
M=[(1, 100), (2, 200), (3, 300), (4, 400)]
However, I want to separate it into M1=[1,2,3,4] and M2=[100,200,300,400].
Here is how I do it at the moment,
M1 = [] M2 = [] for M1,M2 in M: M1.append(M1) M2.append(M2)
I was wondering if there is a simpler and more efficient way to do it, a solution that uses built-in functions in Python.
Just do it:
M1 and M2 will be tuples. You can transform them into lists if you want:
or with a genexp: