Question: Need help with this Python problem set. There is 4 parts to this (A-D). I've already answered these but I would like to see an

Need help with this Python problem set. There is 4 parts to this (A-D). I've already answered these but I would like to see an expert answer with clear explanations to confirm I did this correctly.

A. ) make a function named compute that:

  • Returns the square of any number for integer or floating type values
  • Returns the reverse of the content if it is a string
  • Or returns thevalue None(not the string 'None') if it is another kind of value.

----------------------------------------------------------------------------------------

B. ) Now apply the compute function made in 1A. (above) using map to a list of values. Write this map statement in the new function named map_compute. Return the values as a list (not a map_object). You should be able to do this in ONE single line!

Example function call:

map_compute(['cup', '321', 12, ['x'], 4, True])

Expected returned output:

['puc', '123', 144, None, 16, None]

--------------------------------------------------------------------------------------------

C.) make a new function named filter_compute to remove anyintegervalues that are less than 5 in your map result and return this result as a list. You should be able to this in ONE single line.

Some pseudo-code below:

  • Step 1: Use map to apply compute function from Part 1A to your list (as you did above in 1B)
  • Step 2: Use filter to apply the above constraint to your output of Step 1. You might want to re-factor your filter logic in a separate function (it won't be counted against the single line constraint imposed above)

Example function call:

filter_compute(['cup', '321', 2, ['x'], 4, True])

Expected returned output:

['puc', '123', None, 16, None]

----------------------------------------------------------------------------------

D.) Now that you are an expert in maps and filters, write the above logic from Part 1B & 1C in ONE line using 2 lambda functions, 1 for the map, and 1 for the filter part in the function named lambda_compute. This should be one line with one lambda for the map and one lambda for the filter. DoNOTuse the lambdas to call the functions you already made in the parts above (1A, 1B or 1C), instead make the same logic in a lambda function.

Hint: It could be easier to start with separate lambda functions and then combine then into one.

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 Programming Questions!