Collections.OrderedDict()

Sort by

recency

|

727 Discussions

|

  • + 0 comments
    ordDict = OrderedDict()
    
    for line in sys.stdin:
        strippedItem = line.strip()    
        splitItem = strippedItem.rsplit(" ", 1)    
        if not strippedItem.isnumeric(): 
            if splitItem[0] not in ordDict.keys():
                ordDict[splitItem[0]] = int(splitItem[1])
            else:
                ordDict[splitItem[0]] += int(splitItem[1])
            
    for key in ordDict.keys():
        print(key + " " + str(ordDict.get(key)))
    
  • + 0 comments
    from collections import OrderedDict
    n = int(input())
    ItemPriceDic = OrderedDict()
    for _ in range(n):
        Inp = input().split()
        item_name = ' '.join(Inp[:-1])
        item_price = int(Inp[-1])
        if item_name in ItemPriceDic.keys():
            ItemPriceDic[item_name] += item_price
        else:
            ItemPriceDic[item_name] = item_price
            
    for i in ItemPriceDic:
        print(' '.join(map(str,(i,ItemPriceDic[i]))))
    
  • + 0 comments
    from collections import OrderedDict
    purchases = OrderedDict()
    N = int(input())
    
    for _ in range(N):
        inputs = input().split()
        item = ' '.join(inputs[:-1])
        try:
            purchases[item] += int(inputs[-1])
        except KeyError:
            purchases[item] = int(inputs[-1])
    
    for item, price in purchases.items():
        print(item, price)
    
  • + 0 comments
    from collections import OrderedDict
    
    N=int(input())
    od=OrderedDict()
    for _ in range(N):
        line=input().split()
        item,price=' '.join(line[:-1]),int(line[-1])
        od[item]=od.get(item, 0)+int(price)
    
    for item,price in od.items():
        print(item,price)
        
        
    
  • + 0 comments
    from collections import OrderedDict
    no_of_order = int(input())
    orders = OrderedDict()
    for _ in range(no_of_order):
        order = input().split()
        price = int(order[-1])
        order.remove(order[-1])
        if ' '.join(order) in orders:
            orders[' '.join(order)] += price
        else:
            orders[' '.join(order)] = price
    for item, net_price in orders.items():
        print(item,net_price)