Remove Duplicate Elements From a List in Python Using Counter()

Python Program to Remove Duplicate Elements From a List Using Counter()

# Python Program to Remove Duplicate Elements From a List Using Counter()

from collections import Counter
  
# initializing list
arr = [8, 5, 3, 6, 1, 3, 8, 7, 3]
print ('The original list is : '+ str(arr))

# using Counter() + keys() to remove duplicated from list
temp = Counter(arr)
res = [*temp]

# printing list after removal of duplicate
print('The list after removing duplicates :' ,res)

Output:

The original list is : [8, 5, 3, 6, 1, 3, 8, 7, 3]
The list after removing duplicates : [8, 5, 3, 6, 1, 7]

About The Author

Leave a Reply