Lambda Functions
Which is true about lambda functions?
Lambda functions can be used to control the behaviour of higher order functions
Which of the following function allows you to apply a condition and based on that condition, you obtain the output?
which of the following function allows you to perform an operation on every item present in the list?
What would be the output of the following code:
numbers_1 = [1,2,3,4,5]
result = list(filter(lambda x: x % 2 == 0, numbers_1))
print(result)
What is the output of the following code?
from functools import reduce
numbers_1 = [1,2,3,4,5]
result = reduce(lambda x, y: x*y, numbers_1)
print(result)
What is the output of the following code?
numbers_1 = [1,2,3,4,5]
result = reduce(lambda x, y: x+y, filter(lambda x: x % 2 == 0, numbers_1))
print(result)
What is the output of the following code?
words_list = ["apple", "banana", "cherry"]
result = list(map(lambda x: len(x), words_list))
print(result)
What is the output of the following code?
nums_1 = [2,4,6,8]
result = map(lambda x: x * 2, nums_1)
print(list(result))
What is the output of the following code?
words_list = ['hello', 'world', 'how', 'are', 'you']
result = filter(lambda x: len(x) > 3, words_list)
result = map(lambda x: x.upper(), result)
print(list(result))
What is the output of the following code?
prog_lang = ['Python', 'Java', 'JavaScript', 'C++', 'Ruby']
result = filter(lambda x: len(x) > 4, prog_lang)
result = map(lambda x: x.lower(), result)
print(list(result))