去除列表中不重复的元素,且保证重复元素的次序与原列表一致
'''
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
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"
版权声明:本文为博主原创文章,未经博主允许不得转载。