Adding source code files for Chapter 6
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# lambda1.py to get square of each item in a list
|
||||
|
||||
mylist = [1, 2, 3, 4, 5]
|
||||
new_list = list(map(lambda x: x*x, mylist))
|
||||
print(new_list)
|
||||
@@ -0,0 +1,5 @@
|
||||
# lambda2.py to get even numbers from a list
|
||||
|
||||
mylist = [1, 2, 3, 4, 5,6,7,8,9]
|
||||
new_list = list(filter(lambda x: x % 2 == 0, mylist))
|
||||
print(new_list)
|
||||
@@ -0,0 +1,6 @@
|
||||
# lambda3.py to get product of corresponding item in the two lists
|
||||
|
||||
mylist1 = [1, 2, 3, 4, 5]
|
||||
mylist2 = [6, 7, 8, 9]
|
||||
new_list = list(map(lambda x,y: x*y, mylist1, mylist2))
|
||||
print(new_list)
|
||||
Reference in New Issue
Block a user