Removing duplicates from a list of lists

前端 未结 12 1438
萌比男神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 10:53

    A bit of a background, I just started with python and learnt comprehensions.

    k = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]]
    dedup = [elem.split('.') for elem in set(['.'.join(str(int_elem) for int_elem in _list) for _list in k])]
    

提交回复
热议问题