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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!