728x90
반응형
[mtest04]
# -*- coding: utf-8 -*-
# lambda function : 익명함수
hap01 = lambda a, b: a + b
print(hap01(10,20))
gob = lambda a, b: a * b
print(gob(34,56))
hap02 = lambda a, b, c: a + b + c
print(hap02(7,8,9))
a = [(1, 'one',9), (2, 'two',8), (3, 'three', 7), (4, 'four', 6)]
# one two three four를 기준으로 정렬
a.sort(key=lambda a:a[1])
print(a)
a.sort(key=lambda a:a[2])
print(a)
min01 = (lambda x,y: x if x<y else y)(11,22)
print(min01)
max01 = lambda x,y: x if x>y else y
print(max01(33,44))
# js03_function2_html참고
b = lambda x:(lambda newx: x + newx)
print(b(90)(100))
c = b(90)
print(c)
# 1~100 사이에서 5의 배수 출력
e = lambda x: bool(x%5) #true인 경우 반환(5의 배수가 아닐 경우 true)
five = [i for i in range(1,101) if not e(i)]
print(five)
f = lambda x: x if (x % 5 != 0) else None
res = [i for i in range(1,101) if not f(i)]
print(res)
result = [i for i in range(1,101) if not (lambda x: x if(x%5!=0) else None)(i)]
print(result)
# 결과값
30
1904
24
[(4, 'four', 6), (1, 'one', 9), (3, 'three', 7), (2, 'two', 8)]
[(4, 'four', 6), (3, 'three', 7), (2, 'two', 8), (1, 'one', 9)]
11
44
190
<function <lambda>.<locals>.<lambda> at 0x7ffade2a3820>
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
728x90
반응형
'Language > Python' 카테고리의 다른 글
[python]numpy, matplotlib_그래프 (0) | 2020.10.12 |
---|---|
[python]random_랜덤, 로또 (0) | 2020.10.12 |
[python]함수02_구구단 (0) | 2020.10.08 |
[python]함수01 (0) | 2020.10.08 |
[python]피보나치수열 (0) | 2020.10.08 |