정수 n과 정수 배열 numlist가 매개변수로 주어질 때, numlist에서 n의 배수가 아닌 수들을 제거한 배열을 return하도록 solution 함수를 완성해주세요.
code - 1차
def solution(n, numlist):
answer = []
for i in numlist:
if i%n == 0:
answer.append(i)
return answer
code - 2차
- 한 줄 코딩이 멋있어 보여서 리스트 컴프리헨션 연습
def solution(n, numlist):
return [i for i in numlist if i%n==0]
https://github.com/seonmin5/codingtest_Python
GitHub - seonmin5/codingtest_Python
Contribute to seonmin5/codingtest_Python development by creating an account on GitHub.
github.com
반응형
'Python' 카테고리의 다른 글
[Python/level 1] 문자열 내 p와 y의 개수 - 12916, count() (0) | 2024.08.07 |
---|---|
[Python/level 0] 문자열 정수의 합 - 181849, sum, 리스트 컴프리헨션 (0) | 2024.08.03 |
[Python/level 0] 암호 해독 - 120892, Slicing (0) | 2024.08.03 |
[Python/level 0] 양꼬치 - 120830, O(n) vs O(1) 풀이법 비교 (0) | 2024.08.03 |
[Python/level 0] ad 제거하기 - 181870, not in, pop과 remove를 사용하지 않은 이유 (1) | 2024.08.03 |