Collections.OrderedDict()

Sort by

recency

|

716 Discussions

|

  • + 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}")

  • + 0 comments
    from collections import OrderedDict
    l=[]
    d=OrderedDict()
    for _ in range(int(input())):
        a=input()
        l.append(a)
    
    for i in l:
        j=i.split(" ")
        j[-1]=str(l.count(i)*int(j[-1]))
        d[" ".join(j)]=l.count(i)
    for i in d:
        print(i)
        
    
        
    
        
    
  • + 0 comments
    from collections import OrderedDict 
    ordinary_dictionary = OrderedDict()
    N = int(input())
    
    for _ in range(N):
        shopping = list(map(str,input().strip().split()))
        item = " ".join(shopping[:-1])
        
        if item not in ordinary_dictionary.keys():
            ordinary_dictionary[item] = int(shopping[-1])
        else:
            ordinary_dictionary[item] += int(shopping[-1])
            
    
    for item, product in ordinary_dictionary.items():
        print(str(item) + " " + str(product))