def generate_family_of_partitions(list_of_elements):
    """
    Function that generates the family of partitions

    Parameters
    ----------
    list_of_elements : list
        The collection of elements for which we seek the family of partitions. For example,
        if list_of_elements = [1,2,3], then this function will return [[[1, 2, 3]], [[1], [2, 3]], [[1, 2], [3]], [[2],
        [1, 3]], [[1], [2], [3]]]

    Returns
    -------
    list
        List of the family of partitions

    """

    # Thanks to alexis: https://stackoverflow.com/questions/19368375/set-partitions-in-python
    def partition(l):
        if len(l) == 1:
            yield [l]
            return

        first = l[0]
        for smaller in partition(l[1:]):

            # insert `first` in each of the subpartition's subsets
            for n, subset in enumerate(smaller):
                yield smaller[:n] + [[first] + subset] + smaller[n + 1:]
            # put `first` in its own subset
            yield [[first]] + smaller

    family = []
    for p in partition(list_of_elements):
        family.append(p)

    return family