Removing duplicates from list of lists in Python

后端 未结 5 1478
温柔的废话
温柔的废话 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 20:09

    i am not sure what you meant by "another list", so i assume you are saying those lists inside L

    a=[]
    L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46],['7','a','b']]
    for item in L:
        if not item[0] in a:
            a.append(item[0])
            print item
    

提交回复
热议问题