-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (28 loc) · 761 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
print("Python program to demonstrate map")
# of map.
print("--------------------------")
print("Return double of n")
# Return double of n
def addition(n):
return n + n
# We double all numbers using map()
numbers = (1, 2, 3, 4)
# iterates throuygh numbers object and feeds value into addition
print("old")
result1 = []
for n in numbers:
r = addition(n)
result1.append(r)
print((result1))
print("new")
result = map(addition, numbers)
print(list(result))
# Double all numbers using map and lambda
print("lambda")
result = map(lambda x: x + x, numbers)
print(list(result))
print("Add two lists using map and lambda")
numbers1 = [1, 2, 3]
numbers2 = [4, 5, 6]
result = map(lambda x, y: x + y, numbers1, numbers2)
print(list(result))