Collections.OrderedDict()

  • + 0 comments

    from collections import OrderedDict n = int(input()) item = OrderedDict()

    for _ in range(n): item_name,price = input().rsplit(' ',1) price = int(price)

    if item_name in item:
        item[item_name] += price
    
    else:
        item[item_name] = price
    

    for item_name,item_price in item.items(): print(f'{item_name} {item_price}')