Question: thanks a lot Write a function valid(f, 1) that, given a function f and a list of potential inputs 1, returns a list, tuple, or

 thanks a lot Write a function valid(f, 1) that, given a

thanks a lot

Write a function valid(f, 1) that, given a function f and a list of potential inputs 1, returns a list, tuple, or set of the elements of 1 that are valid inputs to f. How will you know if something is a valid input to f? If you call f on the element and an exception is thrown, you know it was not a valid input For instance, if f is the abs) function, it can only accept integers and floating point numbers. If it is the max() function, it can only accept lists or tuples, if it is the sqrt() function, it can only accept non-negative numbers, etc... # write your answer here from math import sgrt valid(sqrt , [-3, 0, 51) [0, 5] valid(min, [0.3, -0.1, -1, 1, 'cat', '1', [1.3, 211) valid (ord, 'abc', a, 1, 10, 123.3, 2**21])'a' ] def onlystrings(x): cat','1', [1.3, 2]1 if type(x) - str: return True else: raise UserWarning valid(onlystrings, ['cat', 123, [1, 2, 311)-['cat' valid ( set , I ( 1 , 2 ) , smartexpression' , 3, 5 . 14 , [ { ' potato' : ' tomato ' } ? ? ) -[ ( ?, 2 ) , ' smartexpression

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!