Efficiently remove duplicates, order-agnostic, from list of lists

后端 未结 4 1001
感情败类
感情败类 2020-12-21 00:16

The following list has some duplicated sublists, with elements in different order:

l1 = [
    [\'The\', \'quick\', \'brown\', \'fox\'],
    [\'hi\', \'there\'         


        
4条回答
  •  感动是毒
    2020-12-21 00:28

    This:

    l1 = [['The', 'quick', 'brown', 'fox'], ['hi', 'there'], ['jumps', 'over', 'the', 'lazy', 'dog'], ['there', 'hi'], ['jumps', 'dog', 'over','lazy', 'the']]
    s = {tuple(item) for item in map(sorted, l1)}
    l2 = [list(item) for item in s]
    

    l2 gives the list with reverse duplicates removed. Compare with: Pythonic way of removing reversed duplicates in list

提交回复
热议问题