You are viewing a single comment's thread. Return to all comments →
from collections import OrderedDict
items = int(input())
shopping_dict = OrderedDict() for i in range(items):
input_line = input() last_space_index = input_line.rfind(' ') item_name = input_line[:last_space_index] price = input_line[last_space_index + 1:] price = int(price) if item_name in shopping_dict: shopping_dict[item_name] += price else: shopping_dict[item_name] = price
for item_name, price in shopping_dict.items(): print(item_name, price)
Seems like cookies are disabled on this browser, please enable them to open this website
Collections.OrderedDict()
You are viewing a single comment's thread. Return to all comments →
from collections import OrderedDict
items = int(input())
shopping_dict = OrderedDict() for i in range(items):
for item_name, price in shopping_dict.items(): print(item_name, price)