Input Format
The first line contains the number of items, .
The next  lines contains the item's name and price, separated by a space.
Constraints
Output Format
Print the item_name and net_price in order of its first occurrence.

hackerrank collections ordereddict() problem solution in python programming

Problem solution in Python 3 programming language.

from collections import OrderedDict
my_order = OrderedDict()
for i in range(int(input())):
    name,space,price = input().rpartition(' ')
    if name not in my_order:
        my_order[name] = int(price)
    else:
        my_order[name] += int(price)
for item_name, net_price in my_order.items():
    print(item_name,net_price)

Second solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import OrderedDict
d = OrderedDict()
for _ in range(int(input())):
    item, space, quantity = input().rpartition(' ')
    d[item] = d.get(item, 0) + int(quantity)
for item, quantity in d.items():
    print(item, quantity)

Problem solution in Python 2 programming language.

from collections import OrderedDict
my_order = OrderedDict()
for i in range(int(raw_input())):
    name,space,price = raw_input().rpartition(' ')
    if name not in my_order:
        my_order[name] = int(price)
    else:
        my_order[name] += int(price)
for item_name, net_price in my_order.items():
    print item_name,net_price