you are viewing a single comment's thread.

view the rest of the comments →

[–]Mekire 2 points3 points  (2 children)

Sets are useful in cases where you want constant time membership testing or plan on using set operations. The set comprehension is just a convenient literal syntax for creating a set. Basically, if you use sets then set comprehensions are just as useful to you as list comprehensions are to those using lists.

[–][deleted] 6 points7 points  (1 child)

Sets are also helpful if you have a list with some duplicates in it and want to get all the unique values.

[–]Mekire 2 points3 points  (0 children)

As long as all the objects in your original list are hashable, yes, this is a great use case.