0 votes
in Python by
How will you remove duplicate elements from a list?

2 Answers

0 votes
by

There are various methods to remove duplicate elements from a list. But, the most common one is, converting the list into a set by using the set() function and using the list() function to convert it back to a list, if required. ex: list0 = [2, 6, 4, 7, 4, 6, 7, 2]

list1 = list(set(list0)) print (“The list without duplicates : ” + str(list1)) o/p: The list without duplicates : [2, 4, 6, 7]

0 votes
by

We can turn it into a set to do that.

>>> list=[1,2,1,3,4,2]

>>> set(list)

{1, 2, 3, 4}

Related questions

0 votes
asked Feb 11, 2021 in Python by SakshiSharma
+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
...