Removing duplicates from a list of lists

前端 未结 12 1428
萌比男神i
萌比男神i 2020-11-22 10:37

I have a list of lists in Python:

k = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]]

And I want to remove duplicate elements from it. Was if it

12条回答
  •  自闭症患者
    2020-11-22 11:03

    List of tuple and {} can be used to remove duplicates

    >>> [list(tupl) for tupl in {tuple(item) for item in k }]
    [[1, 2], [5, 6, 2], [3], [4]]
    >>> 
    

提交回复
热议问题