What is the output of the following code snippet?def apply_func(L, func): return [func(x) for x in L]apply_func([7.1, 17.9], lambda x: x**3)
Question
What is the output of the following code snippet?def apply_func(L, func): return [func(x) for x in L]apply_func([7.1, 17.9], lambda x: x**3)
Solution
The given code defines a function apply_func that takes a list L and a function func as arguments. It applies func to each element in L and returns a new list with the results.
The function apply_func is then called with a list [7.1, 17.9] and a lambda function lambda x: x**3 as arguments. The lambda function raises its input to the power of 3.
So, the output of the code will be a list where each element is the cube of the corresponding element in the input list.
Let's calculate it:
- The cube of 7.1 is
7.1**3 = 357.911 - The cube of 17.9 is
17.9**3 = 5733.259
So, the output of the code will be [357.911, 5733.259].
Similar Questions
What will be the output of the following Python code?L = [lambda x: x ** 2, lambda x: x ** 3, lambda x: x ** 4] for f in L: print(f(3))
What is the output of the following code?def outer_fun(a, b): def inner_fun(c, d): return c + d return inner_fun(a, b) res = outer_fun(5, 10)print(res)
What does the following lambda function return? f = lambda x: x*2 print(f(3)) Answer( Please choose a correct answer ) CLEAR2369
What will be the output of the following Python code?def fun(): x=15 print(x)x=12fun()Options: Pick one correct answer from belowError151215 12
What will be the output of the following Python code?def func(a, b=5, c=10): print('a is', a, 'and b is', b, 'and c is', c) func(3, 7)func(25, c = 24)func(c = 50, a = 100)1 pointOption 1Option 2Option 3None
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.