Python remove duplicate cases that are in inverted matrix
Question: I have a list that looks like this:

    
    
    relationShipArray = []
    
    relationShipArray.append([340859419124453377, 340853571828469762])
    relationShipArray.append([340859419124453377, 340854579195432961])
    relationShipArray.append([340770796777660416, 340824159120654336])
    relationShipArray.append([340509588065513473, 340764841658703872])
    relationShipArray.append([340478540048916480, 340671891540934656])
    relationShipArray.append([340853571828469762, 340854579195432961])
    relationShipArray.append([340842710057492480, 340825411573399553])
    relationShipArray.append([340825411573399553, 340770796777660416])
    relationShipArray.append([340825411573399553, 340824159120654336])
    relationShipArray.append([340824159120654336, 340770796777660416])
    relationShipArray.append([340804620295221249, 340825411573399553])
    relationShipArray.append([340684236191313923, 340663388122279937])
    relationShipArray.append([340663388122279937, 340684236191313923])
    relationShipArray.append([340859507280318464, 340859419124453377])
    relationShipArray.append([340859507280318464, 340853571828469762])
    relationShipArray.append([340859507280318464, 340854579195432961])
    relationShipArray.append([340854599697178624, 340845885439229952])
    relationShipArray.append([340836561937641472, 340851694759972864])
    relationShipArray.append([340854579195432961, 340853571828469762])
    relationShipArray.append([340844519832580096, 340854599697178624])
    relationShipArray.append([340814054610305024, 340748443670683648])
    relationShipArray.append([340851694759972864, 340836561937641472])
    relationShipArray.append([340748443670683648, 340814054610305024])
    relationShipArray.append([340739498356912128, 340825992832638977])
    

As you can see there are cases that are duplicated. e.g.

    
    
    [340853571828469762, 340854579195432961] 
    

is the same as (but inverted)

    
    
    [340854579195432961, 340853571828469762]
    

What is the best way (with some efficiency but can live without it if need be)
to remove the duplicates from this list? So in this case I would **keep**
`[340853571828469762, 340854579195432961]`, but **remove** the
`[340854579195432961, 340853571828469762]`.


Answer: Use an OrderedDict if you need to keep the order:

    
    
    from collections import OrderedDict
    
    >>> L = [[1, 2], [4, 5], [1,2], [2, 1]]
    >>> [[x, y] for x, y in OrderedDict.fromkeys(frozenset(x) for x in L)]
    [[1, 2], [4, 5]]
    

**EDIT 1**

If the order is not important you can get away with a set:

    
    
    >>> [[x, y] for x, y in set(frozenset(x) for x in L)]
    [[1, 2], [4, 5]]
    

**EDIT 2**

A more generic solution that works for lists of varying lenght, not only with
two elements:

    
    
    [list(entry) for entry in set(frozenset(x) for x in L)]
    [list(entry) for entry in OrderedDict.fromkeys(frozenset(x) for x in L)]
    

