Jul-09-2023, 01:13 PM
Below code is working fine to sum the price for each items. But I could not understand how values-Keys are filled in ordered dict - d.
from collections import OrderedDict n=int(input()) d=OrderedDict() for i in range(n): item,space,price=input().rpartition(' ') price=int(price) print("test",d.keys(),d.values()) if item in d.keys(): d[item]+=price else: d[item]=price for i in d.keys(): print(i ,d[i])