Question: Python Question '''The input alist is a list of numeric type, find the min and max as well as the positions of min and max

Python Question

'''The input alist is a list of numeric type, find the min and max as well as the positions of min and max of the list, return them as ((min, id_of_min), (max, id_of_max)). Requirements: 1. All position counts should start from 1, not 0; 2. When min or max is unique, the returned id should be a scalar, not a list; When min or max are non-unique, the returned id should be a list containing all min or max ids.

E.g., calling (a, ida), (b, idb) = min_and_max([3, 5, 7, 1, 2, 7, 7, 6]) should obtain (a, ida)=(1, 4), (b, idb)=(7, [3, 6, 7]), Note 1: the position count starts with 1, not 0. Note 2: try the above simple example first, make sure your code returns (a, ida)=(1, 4), (a, ida) should not be any of these (1, 3), (1, [3]), or (1, [4]); and (b, idb) should not be (7, [2, 5, 6]).

Beginning of function call shown below

def min_and_max(alist):

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!