Python: Remove Duplicate Items from Nested list

后端 未结 3 921
忘了有多久
忘了有多久 2020-11-30 13:34
mylist = [[1,2],[4,5],[3,4],[4,3],[2,1],[1,2]]

I want to remove duplicate items, duplicated items can be reversed. The result should be :



        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 13:58

    If order is not important:

    def rem_dup(l: List[List[Any]]) -> List[List[Any]]:
        tuples = map(lambda t: tuple(sorted(t)), l)
        return [list(t) for t in set(tuples)]
    

提交回复
热议问题