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.
Collections.OrderedDict()
Collections.OrderedDict()
+ 0 comments from collections import OrderedDict dic = OrderedDict() for i in range(int(input())): lst = input().split() k = ' '.join(lst[0:len(lst) - 1]) v = lst[len(lst) - 1] if k in dic: dic[k] += int(v) else: dic[k] = int(v) for k,v in dic.items(): print(k, v)
+ 0 comments from collections import OrderedDict # Enter your code here. Read input from STDIN. Print output to STDOUT N = int(input()) item_dict = OrderedDict() for i in range(N): tmpl = input().split() size = len(tmpl) item = ' '.join(tmpl[:size-1]) price = int(tmpl[size-1]) if item in item_dict: item_dict[item] = item_dict[item] + price else: item_dict[item] = price [print(i, p) for i,p in item_dict.items()]
+ 0 comments from collections import OrderedDict import re ptn = re.compile(r"\d+") my_Dict = OrderedDict() for _ in range(int(input())): text = input() price = re.search(ptn,text)[0] name = text.replace(price,"").strip() if name in my_Dict: my_Dict[name] += int(price) else: my_Dict[name] = int(price) for name, price in my_Dict.items(): print(name,price)
+ 0 comments from collections import OrderedDict N = int(input()) items_sold = OrderedDict() for _ in range(N): *item_name, net_price = input().split() item_name = ' '.join(item_name) if item_name in items_sold: items_sold[item_name] += int(net_price) else: items_sold[item_name] = int(net_price) for item_name, net_price in items_sold.items(): print(f"{item_name} {net_price}")
+ 0 comments from collections import OrderedDict my_dict = OrderedDict() for _ in range(int(input())): *item, price = input().split() item = ' '.join(item) if item not in my_dict.keys(): my_dict[item] = int(price) else: my_dict[item] += int(price) for key in my_dict: print(key, my_dict[key])
Load more conversations
Sort 615 Discussions, By:
Please Login in order to post a comment