human
I am working on the file "Lectures/Lecture_2/Jupyter_notebook_sheets/functions.ipynb".
The first task is:
Closures (factory functions)
Can you write Python code for it?
assistant
#Here is the Python code you requested.

def v1_multiply_by(m):
    def multiply(n):
        return n * m
    return multiply

multiply_by_7 = v1_multiply_by(7)
print(multiply_by_7(4))

def v2_multiply_by(m):
    return lambda n: n * m

multiply_by_7 = v2_multiply_by(7)
print(multiply_by_7(4))

def multiplications_between_0_and_9():
    multiply_by = []
    for m in range(10):
        # If "lambda n, m = m: n * m" is replaced by "lambda n, m: n * m"
        # then all mulplications are by 9
        multiply_by.append(lambda n, m = m: n * m)
    return multiply_by

multiply_by = multiplications_between_0_and_9()
multiply_by_7 = multiply_by[7]
print(multiply_by_7(4))