Removing Duplicates from Nested List Based on First 2 Elements

后端 未结 3 1022
一整个雨季
一整个雨季 2020-12-19 12:11

I\'m trying to remove duplicates from a nested list only if the first 2 elements are the same, ignoring the third...

List:

L = [[\'el1\',\'el2\',\'va         


        
3条回答
  •  臣服心动
    2020-12-19 12:31

    this should do it:

    In [55]: dict((tuple(x[:2]), x) for x in L).values()
    Out[55]: [['el1', 'el2', 'value2'], ['el1', 'el5', 'value3'], ['el3', 'el4', 'value2']]
    

提交回复
热议问题