You are viewing a single comment's thread. Return to all comments →
I know ordered dictionaries are the norm in modern versions of py3, but added the import just for the spirit of things.
from collections import OrderedDict as od if __name__ == '__main__': n = int(input()) dic = od() for i in range(n): product, price = input().rsplit(' ', 1) dic[product] = int(price) + dic.get(product, 0) print(*(f"{k} {v}" for k, v in dic.items()), sep='\n')
Collections.OrderedDict()
You are viewing a single comment's thread. Return to all comments →
I know ordered dictionaries are the norm in modern versions of py3, but added the import just for the spirit of things.