Question: Python problem. 3. (6 pts) Define the following four sorting functions: each takes an argument that is a list of int or str or both
Python problem.
3. (6 pts) Define the following four sorting functions: each takes an argument that is a list of int or str or both values (otherwise raise an AssertionError exception with an appropriate error message) that will be sorted in a different way. Your function bodies must contain exactly one assert statement followed by one return statement. In parts a-c, create no other extra/temporary lists other than the ones returned by calling sorted. a. (2 pts) Define the mixed sort1 function, which returns the list sorted increasing by the int values and int equivalent of the str values. For example, mixed sort! ([13.1, '2.4] ) returns [1,'213' ,4J. calling mixed sort1(1) prints AssertionError: qlsolution.mixed sortl: 1 non int/str list b. (2 pts) Define the mixed sort2 function, which returns the list sorted first increasing by the int values and then sorted increasing by the int equivalent of the str values. For example, mixed sort (['3',1, '2',4]) returns [1,4, '2', '3'] c. (1 pt) Define the mixed sort3 function, which returns the list sorted first increasing by the int values and then sorted decreasing by the int equivalent of the str values. For example, mixed sort(['3',1, '2',4]) returns [1,4, '3', '2'. Hint: for the key argument, I used a conditional if in the lambda to choose a different tuple for int and str values, so they compare correctly. d. (1 pt) Define the mixed sort4 function, which returns values in the same order as mixed sort3, but here all the values returned are int. For example, mixed sort(['3',1, '2',4]) returns [1,4,3,2]. You may create a temporary list in this function. Hint: I created it using a comprehension
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
