def square_list(list): if utility.is_null(list): return utility.list() else: return utility.cons( square(utility.car(list)), square_list(utility.cdr(list)))
def same_parity_iter(a): """ :type a: FunctionType | object :return: """ if is_null(a): return None else: b = car(a) # type: int if is_even(x - b): return cons(b, same_parity_iter(cdr(a))) else: return same_parity_iter(cdr(a))
def same_parity(x, *z): """ :type x: int :type z: object :rtype: FunctionType """ y = list(*z) def same_parity_iter(a): """ :type a: FunctionType | object :return: """ if is_null(a): return None else: b = car(a) # type: int if is_even(x - b): return cons(b, same_parity_iter(cdr(a))) else: return same_parity_iter(cdr(a)) return cons(x, same_parity_iter(y))
def make_interval(a, b): return utility.cons(a, b)
def make_rectangle(p, q): return utility.cons(p, q)
def make_segment(p, q): return utility.cons(p, q)
def make_point(x, y): return utility.cons(x, y)
from utility import cons, list, append, print_list if __name__ == '__main__': x = list(1, 2, 3) y = list(4, 5, 6) print_list(append(x, y)) print_list(cons(x, y)) print_list(list(x, y))
def make_rectangle(width, height): return utility.cons(width, height)
def subsets(l): if is_null(l): return list(list()) rest = subsets(cdr(l)) return append(rest, map(lambda x: cons(car(l), x) , rest))
def make_rat(n, d): if d < 0: return make_rat(-n, -d) g = gcd(n, d) return utility.cons(n // g, d // g)
def iter(things, answer): if is_null(things): return answer else: iter(cdr(things), cons(answer, square(car(things))))