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 →

  • ryan_a_gard
    3 months ago+ 0 comments
    from collections import OrderedDict
    
    N = int(input())
    items = OrderedDict()
    
    for _ in range(N):
        item_name, net_price = input().rsplit(maxsplit=1)
        items[item_name] = items.get(item_name, 0) + int(net_price)
    
    for item_name, net_price in items.items():
        print(f"{item_name} {net_price}")
    
    2|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy