#!/usr/bin/env python #coding=utf-8 origh_list = [6,3,1,2,4,5,3] new_list = [] for item in origh_list: if not item in new_list: new_list.append(item) print(sorted(new_list))
其实,我们有更简单的方法,python已经内置了这种解决方式,那就是set
#!/usr/bin/env python #coding=utf-8 origh_list = [6,3,1,2,4,5,3] new_list = set(origh_list) print(new_list)
set是一个工厂函数,它会返回给你一个没有重复项的集合,非常方便的帮我们去除重复函数