HackerRank Python - Collections.OrderedDict()

An OrderedDict is a dictionary that remembers the order of the keys that were inserted first. If a new entry overwrites an existing entry, the original insertion position is left unchanged.

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from collections import OrderedDict
  3. order = OrderedDict()
  4. for _ in range(int(input())):
  5. item, space, price = input().rpartition(' ')
  6. order[item] = order.get(item, 0) + int(price)
  7. for item, price in order.items():
  8. print(item, price)

download android app