def mk_matrix(rows, cols, entry_fn):
    """returns rows x cols matrix
    whose (i, j)th entry is entry_fn(i, j)"""
    return [[entry_fn(i, j)
             for j in range(cols)]
            for i in range(rows)]