-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16_lambda.py
More file actions
49 lines (27 loc) · 784 Bytes
/
Copy path16_lambda.py
File metadata and controls
49 lines (27 loc) · 784 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def squared(num): return num * num
# lambda num: num * num
print(squared(2))
addtwo = lambda num: num + 2
print(addtwo(12))
sum_total = lambda a, b: a + b
print(sum_total(10, 8))
#######################
def funcbuilder(x):
return lambda num: num + x
addTen = funcbuilder(10)
addTwenty = funcbuilder(20)
print(addTen(7))
print(addTwenty(7))
#######################
numbers = [3, 7, 12, 18, 20, 21]
squared_nums = map(lambda num: num * num, numbers)
print(list(squared_nums))
############################
odd_nums = filter(lambda num: num % 2 != 0, numbers)
print(list(odd_nums))
###########################
from functools import reduce
numbers = [1, 2, 3, 4, 5, 1]
total = reduce(lambda acc, curr: acc + curr, numbers, 10)
print(total)
print(sum(numbers, 10))