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
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