Collections.OrderedDict()

  • + 0 comments
    from collections import OrderedDict
    menu = OrderedDict()
    n = int(input())
    
    for _ in range(n):
        user_input  = input()
        line = user_input.rsplit(" ", 1)
        item = line[0]
        price = int(line[1])
        
    
    
        if item in menu:
            menu[item] += price
        else:
            menu[item] = price
        
    for thing, total_item in menu.items():
        print(thing, total_item)