Python OrderedDict() function of Collections module

Author: Al-mamun Sarkar Date: 2020-03-26 13:14:06

Python OrderedDict() function of Collections module. The following code shows how to solve the HackerRank Collections.OrderedDict() Python collections problem. OrderedDict remembers the order of the dictionary keys that were inserted first. 

Code:

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)