Algorithm - How to delete duplicate elements in a list efficiently?

前端 未结 16 2143
执念已碎
执念已碎 2020-12-01 04:21

There is a list L. It contains elements of arbitrary type each. How to delete all duplicate elements in such list efficiently? ORDE

16条回答
  •  执笔经年
    2020-12-01 04:45

    In Python

    >>> L = [2, 1, 4, 3, 5, 1, 2, 1, 1, 6, 5]
    >>> a=[]
    >>> for i in L:
    ...   if not i in a:
    ...     a.append(i)
    ...
    >>> print a
    [2, 1, 4, 3, 5, 6]
    >>>
    

提交回复
热议问题