Remove duplicates and original from list

后端 未结 5 945
清酒与你
清酒与你 2020-11-29 12:49

Given a list of strings I want to remove the duplicates and original word.

For example:

lst = [\'a\', \'b\', \'c\', \'c\', \'c\', \'d\', \'e\', \'e\']
         


        
5条回答
  •  没有蜡笔的小新
    2020-11-29 13:38

    You could make a secondary empty list and only append items that aren't already in it.

    oldList = ['a', 'b', 'c', 'c', 'c', 'd', 'e', 'e']
    newList = []
    for item in oldList:
        if item not in newList:
            newList.append(item)
    print newList
    

    I don't have an interpreter with me, but the logic seems sound.

提交回复
热议问题