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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started