I have a list of objects with attributes qt
, cons
and consper
and have to merge all the objects that have the same consper
value. What is the best way to do that? The list is already sorted by consper
.
Example:
With a list of objects of the class house
:
class house():
def __init__(self, qt, cons, consper):
self.qt = qt
self.cons = cons
self.consper = consper
Turn this list:
l = [
house(2, 20, 10),
house(3, 31, 10),
house(6, 70, 11),
house(2, 40, 20),
house(1, 25, 25)]
Into this list:
l_new = [
house(5, 51, 10),
house(6, 70, 11),
house(2, 40, 20),
house(1, 25, 25)]
By adding the first two objects (because their attribute consper is equivalent)