I have the following structure:
('2', 0.30334973335266113)
('4', 0.43178531527519226)
('3', 0.3627113997936249)
('9', 0.5691161155700684)
('2', 0.4603477120399475)
('2', 0.7340329885482788)
('10', 0.4691111445426941)
('13', 0.20860238373279572)
('3', 0.4541565775871277)
('2', 0.4479588568210602)
('2', 0.6090611815452576)
('16', 0.5154575705528259)
('11', 0.4370063543319702)
('12', 0.38097500801086426)
('14', 0.23826521635055542)
('3', 0.39956724643707275)
('12', 0.291579008102417)
('11', 0.4514589309692383)
I want to get an output that adds the probabilities of each of the id there and return the one that has the highest score.
For instance for 3 and 10:
(3, 1.2)
(10, 0.46)
The return should be: (3, 1.2)
summed = {}
lis = [('2', 0.30334973335266113),
('4', 0.43178531527519226),
('3', 0.3627113997936249),
('9', 0.5691161155700684),
('2', 0.4603477120399475),
('2', 0.7340329885482788),
('10', 0.4691111445426941),
('13', 0.20860238373279572),
('3', 0.4541565775871277),
('2', 0.4479588568210602),
('2', 0.6090611815452576),
('16', 0.5154575705528259),
('11', 0.4370063543319702),
('12', 0.38097500801086426),
('14', 0.23826521635055542),
('3', 0.39956724643707275),
('12', 0.291579008102417),
('11', 0.4514589309692383)]
for i in lis:
summed[str(i[0])] = i[1]
This though overrides the keys so only the last seen key and its value gets stored. When inserted a new key I don't want it to be overwritten, I want the value to be added to the existing key.