We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Collections
  4. Collections.OrderedDict()
  5. Discussions

Collections.OrderedDict()

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • jovanjoviemmanu1
    3 months ago+ 0 comments

    from collections import OrderedDict

    n = int(input()) items = OrderedDict()

    for i in range(n): item, price = input().rsplit(' ', 1) net_price = int(price) if item in items: items[item] += net_price else: items[item] = net_price

    for item, net_price in items.items(): print(item, net_price)

    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy