-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
22 lines (16 loc) Β· 689 Bytes
/
test.py
File metadata and controls
22 lines (16 loc) Β· 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from functools import reduce
'''python lambda ν¨μ'''
def hap(x, y):
return x + y
print(hap(10, 20))
print((lambda x, y : x+y)(10, 20))
# map ν¨μμ lambda => map(ν¨μ, 리μ€νΈ)
print(list(map(lambda x:x**2, range(5))))
# reduce ν¨μμ lambda => reduce(ν¨μ, μνμ€)
print(reduce(lambda x, y: x+(y * 2), [0, 1, 2, 3, 4, 5]))
# filter ν¨μμ lambda => filter(ν¨μ, 리μ€νΈ)
print(list(filter(lambda x:x<5, range(40))))
# lambda ν¨μλ λ§ κ·Έλλ‘ ν¨μμ΄λ©°, [lambda λ§€κ°λ³μ : ννμ] νμμμ ννμμ λ§€κ°λ³μλ₯Ό κ³μ λ£λ νμ
data = [[1, 2], [100, 200], [1, 2000]]
data.sort(key=lambda x:x[1], reverse=True)
print(data)