Question: Task 4: Sorting Tables In the lectures you were given the following code for insertion sort: def insert (k, Ist): j - k while j

Task 4: Sorting Tables In the lectures you were given the following code for insertion sort: def insert (k, Ist): j - k while j > 0 and 1st [j-1] > Ist [j]: Ist [j-1] , Ist [j] = 1st [j], Ist [j-1] j = j - 1 def insertion_sort (1st) : for i in range (1, len (n)) : insert (i, Ist) Implement a function sort.table(table, col) that takes as input an n x m table and a column index. The function sorts the rows of the table in non-decreasing order according to the values in the given column. The function does not have a return statement. You should model your function on the insertion sort code. Example: say that we have the following table: jedi = [['Luke' , 'Tatooine' , 'green'], ['Qui-Gon' , 'Coruscant', 'blue'], ['Obi-Wan' , 'Coruscant', 'blue'], ['Rey' , 'Jakku' , 'yellow']] After calling sort_table (jedi, 0), then jedi == [['Luke', 'Tatooine', 'green'], ['Obi-Wan', 'Coruscant', 'blue'], ['Qui-Gon' , 'Coruscant', 'blue'], ['Rey', 'Jakku', 'yellow']]. If we then call sort.table (jedi, 2), then jedi == [['Obi-Wan', 'Coruscant' , 'blue'], ['Qui-Gon', 'Coruscant', 'blue'], ['Luke', 'Tatooine' , 'green'], ['Rey' , 'Jakku', 'yellow']]. Note that the relative ordering is maintained
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
