去除列表中不重复的元素 分类: python 小练习 2013-06-25 14:59 245人阅读 评论(0) 收藏

'''
去除列表中不重复的元素,且保证重复元素的次序与原列表一致
'''
def checkio(data):

    l =[]

    for i in  data:
        
        if data.count(i)>1:
            l.append(i)



    return l

#These "asserts" using only for self-checking and not necessary for auto-testing


if __name__ == "__main__":
    print checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3], "1st example"
    print checkio([1, 2, 3, 4, 5]) == [], "2nd example"
    print checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5], "3rd example"
    print checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9], "4th example"

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/think1988/p/4628149.html