Question
(Python) Duplicate Merging Write a procedure that receives an inventory and modifies it in such a way that duplicate products are merged. All the quantities
(Python) Duplicate Merging Write a procedure that receives an inventory and modifies it in such a way that duplicate products are merged. All the quantities for the same product has to be added and the order in which products appear for the first time in the list must be preserved.
Sample Input
Choc 5 Vani 10 Stra 7 Choc 3 Stra 4 END
Sample Output
[['Choc', 8], ['Vani', 10], ['Stra', 11]]
def process_input(lst): result = [] for l in lst: str = l.split(' ') result.append([str[0], int(str[1])]) return result
def merge_products(invent): # your code here
# DONT modify the code below string = input() lines = [] while string != "END": lines.append(string) string = input() inventory1 = process_input(lines) merge_products(inventory1) print(inventory1)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started