I have a list
[[0.5, 2], [0.5, 5], [2, 3], [2, 6], [2, 0.6], [7, 1]]
I require the output from summing the second element in each sublist f
Using Pandas, you can retain the original 'order' of the data:
pairs = [[0.5, 2], [0.5, 5], [2, 3], [2, 6], [2, 0.6], [7, 1]] df = pd.DataFrame(pairs) >>> [tup[0] for tup in zip(df.groupby(0, sort=False, as_index=False).sum().values.tolist())] [[0.5, 7.0], [2.0, 9.6], [7.0, 1.0]]