from typing import List


def dedupe_loops(loops: List[List]) -> List:
    """
    Deduplication of loops with same members.

    For example: for nodes 1, 2, 3 in the graph below

        [
            [0, 1, 1],
            [1, 0, 1],
            [1, 1, 0],
        ]

    Loops of length 3 are 0->1->2 and 0->2->1. We only retain 1 of these loops after dedupe.

    Example 2:
    For the following graph:
            [
                [0, 1, 1, 1],
                [1, 0, 1, 1],
                [1, 1, 0, 1],
                [1, 1, 1, 0],
            ]

    Pictorially this is the network
    1 ---------2
    | *      * |
    |    *     |
    |  *    *  |
    4----------3

    Loops of length 4 are:
        [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]]

    After deduplication we will only retain [0, 1, 2, 3]

    """
    seen_sets = set()
    filtered = []
    for l in loops:
        loop = l[:]
        l.sort()
        l = tuple(l)
        if l not in seen_sets:
            seen_sets.add(l)
            filtered.append(loop)
    return filtered