$24
In Python, a function can be an argument to another function. The following code snippet takes Python’s built-in function print and passed it as an argument:
Q.1 Write a function order(p, q, n) that takes two multi-element tuples p and q, and compare the element at index n, returns True if p[n] > q[n]. Examples:
Q.2 Use order to implement a function first_max(order_f, l, n). l is a list of tuples, and the function returns the first largest tuple in l. The comparison of order is done using order you implemented in B.1 (i.e. a tuple p is larger than q if p[n] > q[n]).
Example -- (‘B’, 6),(‘X’, 6) and (‘P’, 6) are all the largest on index 1, but (‘B’,
6) is the correct result because it is the first largest:
Q.3 Implement a function last_max(order_f, l, n), this time returns the last one. Constraints: 1) you can not invoke first_max on a reversed list, 2) you must not modify the order function, and you can only use order_f to test order of two tuples.
Example: this time (‘P’, 6) is the last largest