Skip to content

Instantly share code, notes, and snippets.

Created June 30, 2020 00:19
What would you like to do?
CS61A SU20 one-liner challenge for disc02, Q1.6
import doctest
def make_keeper(n):
"""Returns a function which takes one parameter cond and prints out
all integers 1..i..n where calling cond(i) returns True.
>>> def is_even(x):
... # Even numbers have remainder 0 when divided by 2.
... return x % 2 == 0
>>> make_keeper(5)(is_even)
return lambda cond: list(map(print, filter(cond, range(1, n + 1)))) and None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment