Created
September 15, 2022 19:23
-
-
Save kmicinski/6228f74231ff2701e85ce1e664c2094b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def take_first_n(lst, f, n): | |
ret_lst = [] | |
for element in lst: | |
if (n == 0): | |
break | |
if (f(element)): | |
ret_lst.append(element) | |
n = n - 1 | |
return ret_lst | |
print(take_first_n([1,2,3,4,5],lambda x: x % 2 == 0,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment