반응형
n의 배수 고르기
1안) solution.py
def solution(n, numlist):
answer = []
for num in numlist:
if (num % n == 0):
answer.append(num)
return answer
2안) solution.py
def solution(n, numlist):
answer = []
answer = list(filter(lambda num: num % n == 0, numlist))
return answer
3안) solution.py
def solution(n, numlist):
answer = []
answer = [num for num in numlist if num % n == 0]
return answer
파이션 lambda() 함수
x = lambda a: a + 10
print(x(5))
15
x = lambda a, b: a * b
print(x(5, 6))
30
def myfunc(n):
return lambda a : a * n
mytripler = myfunc(3)
print(mytripler(11))
33
참고URL
- w3schools : https://www.w3schools.com/python/python_lambda.asp
- w3schools : https://www.w3schools.com/python/gloss_python_lambda.asp
- w3schools : https://www.w3schools.com/python/python_operators.asp
- 프로그래머스(코딩테스트 연습) : https://school.programmers.co.kr/learn/courses/30/lessons/120905
def myfunc(n): 람다 a 반환 : a * n mytripler = myfunc(3) print(mytripler(11))
728x90
반응형
'스크립트' 카테고리의 다른 글
What Is My IP?(myip) (0) | 2023.02.03 |
---|---|
[스크립트] python beautifulsoup4 (0) | 2023.01.17 |
[코딩테스트 입문] 자릿수 더하기 (0) | 2022.12.02 |
[코딩테스트 입문] 짝수와 홀수 (0) | 2022.11.30 |
[코딩테스트 입문] 평균 구하기 (0) | 2022.11.30 |