Collections.OrderedDict()

  • + 0 comments
    from collections import OrderedDict
    
    N = int(input())
    
    items_dict = OrderedDict()
    for i in range(N):
        item_list = list(input().split())
        price = int(item_list[-1])
        item_list.pop()
        item_name = " ".join(item_list[::])
        
        if item_name in items_dict.keys():
            old_price = int(items_dict[item_name])
            new_price = old_price + price
            items_dict[item_name] = new_price
        else:
            items_dict[item_name] = price
    
    
    for item in items_dict:
        print(item, items_dict[item])