Removing duplicates from list of lists in Python

后端 未结 5 1482
温柔的废话
温柔的废话 2020-12-02 19:40

Can anyone suggest a good solution to remove duplicates from nested lists if wanting to evaluate duplicates based on first element of each nested list?

The main list

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 19:52

    If the order does not matter, code below

    print [ [k] + v for (k, v) in dict( [ [a[0], a[1:]] for a in reversed(L) ] ).items() ]
    

    gives

    [['2', '5', '6'], ['14', '65', '76'], ['7', '12', '33']]

提交回复
热议问题