def create_levels(levels, base_factory):
    """Create a multidimensional array

    :param levels: An Iterable if ints representing the size of each level
    :param base_factory: A nullary function that returns a new instance of the basic unit of the array
    :return: Nested lists
    """

    def loop(current, rest):
        if len(rest) == 0:
            return [base_factory() for _ in range(current)]
        else:
            return [loop(rest[0], rest[1:]) for _ in range(current)]

    return loop(levels[0], levels[1:])