Question: Python 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

Python

Python Q.1 Write a function order (p,q,n) that takes two multi-element tuples

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: morder((1,2,3),(2,1,4),0) False order((1,2,3),(2,1,4),1) True order((1,2,3),(2,1,4),2) False Q.2 Use order to implement a function first_max (order_f, 1,n ) . 1 is a list of tuples, and the function returns the first largest tuple in 1 . 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: tuplst =[(X,5),(B,6),(PP,4),(X,3),(B,5),(P,6)] print(first_max(order, tuplst, 1)) (B,6) Q.3 Implement a function last_max (order_ 1,1,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 > tuplst =[Cx,5),(CB,6),(CP,4),(X,3),(CB,5),CP,6)] > print(last_max(order, tuplst, 1)) (p,6)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!