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.
for i in range(n):
item, price = input().rsplit(' ', 1)
net_price = int(price)
if item in items:
items[item] += net_price
else:
items[item] = net_price
for item, net_price in items.items():
print(item, net_price)
Collections.OrderedDict()
You are viewing a single comment's thread. Return to all comments →
from collections import OrderedDict
n = int(input()) items = OrderedDict()
for i in range(n): item, price = input().rsplit(' ', 1) net_price = int(price) if item in items: items[item] += net_price else: items[item] = net_price
for item, net_price in items.items(): print(item, net_price)