Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

5. Develop the succession planning review.

Answered: 1 week ago