I need to do the opposite of this
Multiple Tuple to Two-Pair Tuple in Python?
Namely, I have a list of tuples
[(1,2), (3,4), (5,6)]
and need to produce this
[1,2,3,4,5,6]
I would personally do this
>>> tot = []
>>> for i in [(1,2), (3,4), (5,6)]:
... tot.extend(list(i))
but I’d like to see something fancier.
The most efficient way to do it is this:
output
Here is the comparison I did for various way to do it in a duplicate question.
I know someone is going to suggest this solution
But don’t use it, it will create a new intermediate result list for each step! unless you don’t care about performance and just want a compact solution.
For more details check Alex’s answer
In summary: sum is faster for small lists, but the performance degrades significantly with larger lists.