Question: Please write a Python function named sort_product_by_discount that gets a list of products as input and sort them based on the discount in descending order.

Please write a Python function named sort_product_by_discount that gets a list of products as input and sort them based on the discount in descending order. On the main function, create a list of products and pass it as input to the function and prints out the sorted list of items based on discount. Please print the product with highest discount too. You may use the following example code for sorting.

# take second element for sort def takeSecond(elem): return elem[1] # random list random = [(2, 2), (3, 4), (4, 1), (1, 3)] # sort list with key random.sort(key=takeSecond, reverse=True)

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!