def subtract(x, y): """ Subtracts y from x and returns the difference :param x: (int) :param y: (int) :return: (int) x-y """ return x - y def add(x, y): """ Adds x to y and returns the sum :param x: (int) :param y: (int) :return: (int) x+y """ return x + y def multiply(x, y): """ Multiplies x to y and returns the product :param x: (int) :param y: (int) :return: (int) x*y """ return x * y def exponent(x, y): """ Raises x to the power of y and returns it :param x: (int) :param y: (int) :return: (int) x^y """ return x ** y def add2(values): """ Receives a tuple of two numbers and returns their sum :param values: (tuple of numbers) :return: (int) values[0] + values[1] """ (x, y) = values return x + y def double(x): """ Doubles x and returns it :param x: (int) :return: (int) 2*x """ return 2 * x def is_even(num): """ Returns whether num is an even number :param num: (int) :return: (bool) whether num is an even number """ return num % 2 == 0 def apply_function(some_function, x, y): """ Calls some_function passing to it x and y as arguments and returns the result :param some_function: (function) a function that takes two parameters :param x: (Any) :param y: (Any) :return: (Any) """ return some_function(x, y) def apply_function_to_list(f, some_list): """ Calls f on each item of some_list and returns the results in a list :param f: (function) a function that takes one parameter :param some_list: (list) :return: (list) """ result = [] for val in some_list: result.append(f(val)) return result def apply_function_to_tuple(f, some_list): """ Calls f on each tuple of some_list and returns the results in a list :param f: (function) a function that takes two parameters :param some_list: (list) a list of 2-tuples :return: (list) """ result = [] for (x, y) in some_list: result.append(f(x, y)) return result def filter_list(some_function, some_list): """ Returns a list of all elements of some_list that would return True when passed to some_function :param some_function: (function) a function that takes one parameter and returns a bool :param some_list: (list) :return: (list) """ result = [] for val in some_list: if some_function(val): result.append(val) return result def kinda_crazy(num): def multiplier(x): return num * x return multiplier def crazy(num): return lambda x: num * x