-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23_lambda.py
More file actions
32 lines (24 loc) · 789 Bytes
/
23_lambda.py
File metadata and controls
32 lines (24 loc) · 789 Bytes
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
def double(x):
return x*2
print(double(9))
# lambda
doubled = lambda num : num * 2
print(double(8))
squared = lambda num : num * num
print(squared(8))
add = lambda x, y : x + y
sum = add(2,3)
print(sum)
numbers = [4,5,6,7,8,9,4,5,6,10]
doubled_numbers = map(lambda num : num * 2 , numbers)
print(doubled_numbers) # <map object at 0x000001FE2C4CB340>
print(list(doubled_numbers)) # [8, 10, 12, 14, 16, 18, 8, 10, 12, 20]
actors = [
{'name' : 'hardy' , 'age' : 20 },
{'name' : 'iron man' , 'age' : 62},
{'name' : 'natasha' , 'age' : 56 },
{'name' : 'nolan' , 'age' : 34 },
{'name' : 'thor' , 'age' : 45 },
]
juniors = filter(lambda actor : actor['age'] < 40 , actors)
print(list(juniors)) # [{'name': 'hardy', 'age': 20}, {'name': 'nolan', 'age': 34}]