In this HackerRank Collections.OrderedDict() problem solution you are the manager of the supermarket. and you have a list of N items together with their prices that consumers bought on a particular day. and your task is to print each item name and net price in order of it's first occurrence.


HackerRank Collections.OrderedDict() in python problem solution

HackerRank Collections.OrderedDict() problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import OrderedDict
n = input()
order = OrderedDict()
for _ in range(n):
    item = raw_input().split()
    key = ' '.join(item[:-1])
    if key in order:
        order[key] += int(item[-1])
    else:
        order[key] = int(item[-1])
for k, v in sorted(order.items()):
    print k, v