Reference no: EM132357066
Question
Define the max_x function, which takes two arguments: (1) a function -call it f- (of one parameter)and (2) any iterable that produces values that can be passed as arguments to f.
When max_x is called, itreturns the value in the iterable for which f returns the maximum (if multiple values in the iterable havethe same maximum when f is called on them, you may return any of these values).
For example: if we callmax_x( cos, frange(-1.5,1.5,.1) ), it should return 0.0, because cos(0.0) is 1.0 and the cos of anyother value in this range is less than 1.0. If the iterable produces no values, then max_x should raise theValueError exception.
(a) Write the max_x function using looping/ifs, creating no lists (or any other data structure).
modify this function that is given:
def max_x(f: callable, values: Iterable) -> object:
pass