Monday, January 4, 2021

LAMBDA PRACTICE 2

Lambdapract
In [1]:
my_list = [1, 5, 4, 6, 8, 11, 3, 12]

new_list = list(filter(lambda x: (x%2 == 0) , my_list))

print(new_list)
[4, 6, 8, 12]
In [5]:
my_list = [1, 5, 4, 6, 8, 11, 3, 12]
nl=list(filter(lambda y:(y%3==0),my_list))
nl
Out[5]:
[6, 3, 12]
In [3]:
# Program to double each item in a list using map()

my_list = [1, 5, 4, 6, 8, 11, 3, 12]

new_list = list(map(lambda x: x * 2 , my_list))

print(new_list)
[2, 10, 8, 12, 16, 22, 6, 24]
In [6]:
my_list = [1, 5, 4, 6, 8, 11, 3, 12]

new_list = list(map(lambda x: x + 2 , my_list))

print(new_list)
[3, 7, 6, 8, 10, 13, 5, 14]
In [ ]:
 

No comments:

Post a Comment