How can I remove duplicates in array for Python?

0 votes

1 Answer

0 votes
No avatar answered by (18.7k points)
selected by
 
Best answer

You can use the set() method to remove duplicates from a list. The set() method will take any iterable as an argument and return a set object of unique elements.

Example:

my_list = [1,2,3,4,3,2,1]
my_set = set(my_list)

print(my_set)
# Output: {1, 2, 3, 4}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...