def preallocate(dim1, dim2=None):
    """
    Preallocate a list by creating either [None] * dim1
    or [[None] * dim2] * dim1. I use for loop to break reference

    Parameters:
    ----------
    dim1 : length of list
    dim2 : if not None, each element is also a list of None

    Returns:
    ----------
    allocated_list : pre-allocated placeholders
    """
    allocated_list = None
    if dim1 > 0:
        if dim2 is None:
            allocated_list = [None for _ in range(dim1)]
        else:
            allocated_list = [[None for _1 in range(dim2)] for _2 in range(
                dim1)]
    return allocated_list
