Home > Backend Development > Python Tutorial > python remove duplicate elements from list

python remove duplicate elements from list

王林
Release: 2020-05-13 14:41:01
Original
4126 people have browsed it

python remove duplicate elements from list

Can be implemented using the append method.

First set up a temporary list to save the results, and then traverse the original list from the beginning. If there is no current element in the temporary list, add it.

Specific code:

Given a list, it is required to delete duplicate elements in the list.

listA = ['python','语','言','是','一','门','动','态','语','言']
Copy after login
def deleteDuplicatedElementFromList2(list):
        resultList = []
        for item in list:
                if not item in resultList:
                        resultList.append(item)
        return resultList
Copy after login

Result:

#['python', '语', '言', '是', '一', '门', '动', '态']
Copy after login

Recommended tutorial: python tutorial

The above is the detailed content of python remove duplicate elements from list. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template