HackerRank Python - Collections.OrderedDict()




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)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube