Home > Article > Backend Development > 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','语','言','是','一','门','动','态','语','言']
def deleteDuplicatedElementFromList2(list): resultList = [] for item in list: if not item in resultList: resultList.append(item) return resultList
Result:
#['python', '语', '言', '是', '一', '门', '动', '态']
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!