Collections.OrderedDict()

  • + 0 comments
    from collections import OrderedDict
    
    od = OrderedDict()
    
    for i in range(int(input())):
        item, price = input().rsplit(maxsplit=1)
        
        if item in od:
            od[item] += int(price)
        else:
            od[item] = int(price)
            
    
    for items, price in od.items():
        print(items, price)