Lab - 5
Lab - 5
Lab - 5
x = lambda a : a + 10
print(x(5))
# Defining a function
def mul(i):
return i * i
5IT Python
Aayush Desai IU21412200
• Note: Aniterable in Python is an object that you can iterate over. It is possible to
loop over aniterable and return items that are in it.
•
• The syntax for the filter() function in Python is -
filter(function, iterable)
nums = {1,2,3,4,5}
m = map(lambda x : x*3 , nums)
print(f"The triple of all numbers in a given list of integers are: {list(m)}")
O/P:
The triple of all numbers in a given list of integers are: [3, 6, 9, 12, 15]
5IT Python
Aayush Desai IU21412200
• Write a Python program to add three given lists using Python map
and lambda.
num1 = [1,2,3]
num2 = [4,5,6]
num3 = [7,8,9]
m = map(lambda x,y,z : x+y+z , num1,num2,num3)
print(f"The addition of all given lists are: {list(m)}")
O/P:
The addition of all given lists are: [12, 15, 18]
Animal = ["Dog","Cat","Lion"]
m = list(map(list,Animal))
print(f"listify the list of given strings are: {m}")
O/P:
listify the list of given strings are: [['D','o','g'], ['C','a','t'], ['L','i','o', 'n']]
num=[10,20,30]
index=[1,2,3]
m=list(map(pow,num,index))
print(f"Power of the numbers are: {m}")
O/P:
Power of the numbers are: [10, 400, 27000]
5IT Python
Aayush Desai IU21412200
num=[34,0,-1,53]
m=list(filter(lambda x: x>0 ,num))
print(f"Positive numbers in the list: {m}")
O/P:
Positive numbers in the list: [34, 53]
num=[1,2,3,4,5,6,7,8,9,10]
m=list(filter(lambda x: x%2==0 ,num))
print(f"Even numbers in the list: {m}")
O/P:
Even numbers in the list: [2, 4, 6, 8, 10]
O/P:
Vowel in the list: a
Vowel in the list: e
Vowel in the list: i
Vowel in the list: o
5IT Python
Aayush Desai IU21412200
5IT Python