Question: Python Question 1: map square_or_cube In this question, we will be exploring the map() function that allows a user function to be applied on every

Python

Question 1: map square_or_cube

In this question, we will be exploring the map() function that allows a user function to be applied on every element of the list without having to iterate over the list using for or while loops. Complete the following function: square_or_cube that either squares or cubes an list of integers. For example if the input to the function is ([1, 2, 4], 'square') then the values [1, 4, 16] would be returned since these are the respective squares of each of the values in the input list. However if the incrementer parameters was set to cube then the function should return [1, 8, 64] since these are the cubed values of the input list. Note: Make sure to cast the output of the call to the map() function to a list() type since map() returns a map_object. Also, make sure to use the map() function. The autograder will check if you have used the map() function.

def square_or_cube(values, incrementer='square'): """ This function will either square all the elements of the values list or it will cube all the elements of the values list depending on if the incrementer paramter is 'square' or 'cube' Parameters ---------- values: list of integers to square or cube incrementer: string parameter that is either `square` or `cube` Returns ------- A list of integers """ # YOUR CODE HERE return vals

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!