Collections.OrderedDict()

  • + 0 comments

    from collections import OrderedDict items = OrderedDict()

    number_of_items = int(input())

    for _ in range(number_of_items): *item_name_parts , price = input().split() item_name = " ".join(item_name_parts) price = int(price)

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

    for item , total in items.items(): print(f"{item} {total}")