+1 vote
in Programming Languages by (56.8k points)
How can I remove duplicate elements from a given list without using any loop logic?

E.g.

Input list: [1, 2, 3, 4, 4, 4, 5, 5]

output list: [1, 2, 3, 4, 5]

1 Answer

+3 votes
by (74.2k points)
selected by
 
Best answer

You can apply the set() function to the given list to remove duplicates and then apply the list() function to cast the set to list.

Here is an example:

>>> aa = [1, 2, 3, 4, 4, 4, 5, 5]

>>> aa

[1, 2, 3, 4, 4, 4, 5, 5]

>>> list(set(aa))

[1, 2, 3, 4, 5]

Related questions


...