可以使用append方法实现。
首先设一个临时列表保存结果,然后从头遍历原列表,如临时列表中没有当前元素则追加。
具体代码:
给定一个列表,要求删除列表中重复元素。
listA = ['python','语','言','是','一','门','动','态','语','言']
def deleteDuplicatedElementFromList2(list): resultList = [] for item in list: if not item in resultList: resultList.append(item) return resultList
结果:
立即学习“Python免费学习笔记(深入)”;
#['python', '语', '言', '是', '一', '门', '动', '态']
推荐教程:python教程
以上就是python删除list中的重复元素的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号