반응형
In Python, there is a built-in filter function that operates similarly to JS's filter. For more information on how to use this function, visit https://docs.python.org/3/library/functions.html#filter
The solution would work like the following:
get_even_numbers([2,4,5,6]) => [2,4,6]
Solution:
def get_even_numbers(arr, condition = lambda x: x % 2 == 0):
return [i for i in arr if condition(i)]
def get_even_numbers(arr):
return list(filter(lambda x: x % 2 == 0, arr))
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1110. No oddities here (0) | 2022.11.10 |
---|---|
1109. Sentence Smash (0) | 2022.11.09 |
1107. I love you, a little , a lot, passionately ... not at all (0) | 2022.11.07 |
1106. Grasshopper - Messi Goals (0) | 2022.11.07 |
1105. Remove exclamation marks (0) | 2022.11.05 |