Python 列表元素排重uniq

 # -*- coding: gbk -*-

 def uniq(ls):
lsCopy=[e for e in ls]
for i in xrange(1,len(ls)):
for j in xrange(i):
if ls[j]!=ls[i]:
pass
else:
lsCopy.remove(ls[i])#如果有removeAt(index)方法更好
return lsCopy if __name__=='__main__':
ls=[1,2,3,4,5,6,7,8,9,7,2,3,6]
print uniq(ls)
结果:[1, 4, 5, 8, 9, 7, 2, 3, 6]#remove(e)删除时从列表头开始找e
上一篇:js/jq和a标签(刷新/ajax/对话框/循环/select选中/checkbox选中/id的获取//数据处理成钱的格式)//js/jq分页


下一篇:Linux 下卸载MySQL 5