7. Write a python program to generate a lambda function to separate the odd and even number from 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 integers: [22, 56, 77, 99, 45, 36, 87, 93, 5, 78, 2, 66]
Even numbers from the said list: [22, 56, 36, 78, 2, 66]
Odd numbers from the said list: [77, 99, 45, 87, 93, 5]
Sample Answer:
list_a = [22, 56, 77, 99, 45, 36, 87, 93, 5, 78, 2, 66] print("The initial list of integers:", list_a) even_list_a = list(filter(lambda x: x%2 == 0, list_a)) print("\nEven numbers from the said list:", even_list_a) odd_list_a = list(filter(lambda x: x%2 != 0, list_a)) print("\nOdd numbers from the said list:", odd_list_a )
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)