8. Write a python program to generate a lambda function to get the power of two on a list of numbers, list_a as provided in the following output.
The output is:
list_a = [22, 56, 77, 99, 45, 36, 87, 93, 5, 78, 2, 66]
Expected Answer:
The initial list of numbers: [3, 22, 36, 45, 56, 77, 87, 93]
The power of two for all elements in list: [9, 484, 1296, 2025, 3136, 5929, 7569, 8649]
Sample Answer:
list_a = [3, 22, 36, 45, 56, 77, 87, 93] print("The initial list of numbers:", list_a) power2_list_a = list(map(lambda x: x ** 2, list_a)) print("\nThe power of two for all elements in list:", power2_list_a)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)