Question: Provide Simple Python Code for the following function with comments and a screenshot of the code: We have the following rectangle records in a list
Provide Simple Python Code for the following function with comments and a screenshot of the code:


We have the following rectangle records in a list of dictionaries. rectangle_records = [{"ID": "Rect1", "Length": 40, "Breadth": 25, "Color": "red"}, {"ID": "Rect2", "Length": 30, "Breadth": 20, "Color": "blue"}, {"ID": "Rect3", "Length": 70, "Breadth": 45, "Color": "green"}, {"ID": "Rect4", "Length": 20, "Breadth": 10, "Color": "purple"}] Using Insertion Sort, Write a function sort_rectangles that takes rectangle_records and record_title as a parameter and sort the rectangle_records in ascending order by record_title. You need to return the updated rectangle_records list. NOTE: The type of record_title input can be ID, Length, Breadth, or Color. >>> sort_rectangles (rectangle_records, "ID") [{"ID": "Recti", "Length": 40, "Breadth": 25, "Color":"red"}, {"ID": "Rect2", "Length": 30, "Breadth": 20, "Color": "blue"}, {"ID": "Rect3", "Length": 70, "Breadth": 45, "Color": "green"}, {"ID": "Rect4", "Length": 20, "Breadth": 10, "Color": "purple"}] >>> sort_rectangles (rectangle_records, "Length") [{'ID': 'Rect4', 'Length': 20, 'Breadth': 10, 'Color': 'purple'}, {'ID': Rect2', 'Length': 30, 'Breadth': 20, 'Color': 'blue'}, {'ID': 'Rectl', 'Length': 40, 'Breadth': 25, 'Color': 'red'}, {'ID': 'Rect3', 'Length': 70, 'Breadth': 45, 'Color': 'green'}] >>> sort_rectangles (rectangle_records, "Breadth") [{'ID': 'Rect4', 'Length': 20, 'Breadth': 10, 'Color': 'purple'}, {'ID': 'Rect2', 'Length': 30, 'Breadth": 20, 'Color': 'blue'}, {'ID': 'Recti', 'Length': 40, 'Breadth': 25, 'Color': 'red'}, {'ID': 'Rect3', 'Length': 70, 'Breadth': 45, 'Color': 'green'}] >>> sort_rectangles (rectangle_records, "Color") [{'ID': 'Rect2', 'Length': 30, 'Breadth': 20, 'Color': 'blue'}, {'ID': 'Rect3', 'Length': 70, 'Breadth': 45, 'Color': 'green'}, {'ID': 'Rect4', 'Length': 20, 'Breadth': 10, 'Color': 'purple'}, {'ID': 'Rectl', 'Length': 40, 'Breadth': 25, 'Color': 'red'}]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
