I am iterating over such objects and creating a list of lists.
Something like this:
#data.py
values = []
for o in objects:
data = [o.day, o.seconds]
values.append(data)
So that gives me, for example:
[['27/2', 34], ['23/2', 21], ['25/2', 11], ['27/2', 38]]
But I need to make an additional operation. If data[0] (day) is already in values, I don’t want to append data, I want to add data[1] to the existing object’s data[1].
So from the above list, what I really want is:
[['27/2', 72], ['23/2', 21], ['25/2', 11]]
I can do the operation without a list, but, at the end, I need to convert it to a list for final use.
Here’s how to use a
defaultdictHere’s a way using a
CounterYou can get a list from values like this