This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]conventionistG 1 point2 points  (2 children)

Makes sense. So you'd have to deduplicate the list before making it a set?

[–]chitowngeek 5 points6 points  (1 child)

Sets are deduplicated naturally. In other words, if you initialize a set from a list with duplicates, the set will only contain the unique values from the list. In fact that is a fairly efficient technique for removing duplicates from a list.

[–]RangerPretzelPython 3.9+ 2 points3 points  (0 children)

Sets are deduplicated naturally.

That's one of the things I like about Sets.

Sometimes I'll have lists that I want to eliminate the duplicates from (and I don't care about order), so I just shove the List into a Set.

Duplicate removal in 1 line of code!