Collections.OrderedDict()

Sort by

recency

|

718 Discussions

|

  • + 0 comments

    Here is HackerRank Collections.OrderedDict() in python solution - https://programmingoneonone.com/hackerrank-collections-ordereddict-solution-in-python.html

  • + 0 comments

    This is a bit of a wierd question, implying the computer is input lots of different lines instead of just a single input, for _ in range(int(input())): print (input())

  • + 1 comment
    from collections import OrderedDict
    
    n = int(input())
    item_list = OrderedDict()
    for _ in range(n):
        item = input().split()
        key = ' '.join(item[:-1])
        value = int(item[-1])
        item_list[key] = item_list.get(key,0)+value
    for k,v in item_list.items():
        print(k,v)
    
  • + 0 comments

    from collections import OrderedDict items= OrderedDict() n= int(input()) for _ in range(n): item,space, net_price= input().rpartition(' ') items[item]= items.get(item,0)+ int(net_price) print(*[f"{item} {price}" for item, price in items.items()], sep='\n')

  • + 0 comments

    from collections import OrderedDict items = OrderedDict()

    number_of_items = int(input())

    for _ in range(number_of_items): *item_name_parts , price = input().split() item_name = " ".join(item_name_parts) price = int(price)

    if item_name in items:
        items[item_name] += price
    else:
        items[item_name] = price
    

    for item , total in items.items(): print(f"{item} {total}")