Reputation: 4142
I have no idea what the title should be, so please feel free to modify it.
I have a massive (millions) list of tuples which look like this:
tuples = list(zip(grid, flattened_values, timestamps))
list(tuples[85864725])
>>> [(1000, -34.25, 50.625), 4.4577124419932667e-10, datetime.datetime(2012, 7, 5, 0, 0)]
I want the result to look like this:
>>> [1000, -34.25, 50.625, 4.4577124419932667e-10, datetime.datetime(2012, 7, 5, 0, 0)]
The best thing I could come up with is:
(tuples[85864725][0][0],tuples[85864725][0][1],tuples[85864725][0][2],tuples[85864725][1])
What is the best way to achieve this? Given that there are millions of tuples, I need a solution which is as performant (in terms of speed) as possible.
Any ideas?
Upvotes: 1
Views: 280
Reputation: 282026
Unpack the tuples from grid
with *
:
tuples = [(*x, y, z) for (x, y, z) in zip(grid, flattened_values, timestamps)]
Upvotes: 2