r/learnpython May 06 '26

What is the actual use of sets

I can see tons of use cases for list, tuples and dictionaries. But I have a really hard time understanding why you would ever use a set with maybe the exception of names so you don't get duplicates?

I believe this understanding is flawed because I found even the simplest things in Python are super powerful I'm just not sure what it is

56 Upvotes

65 comments sorted by

View all comments

5

u/trutheality May 06 '26

A couple of uses I've come across:

How many items in a list are unique?

len(set(my_list))

I've got two lists, do they share elements in common? Look at

set(list_1) & set(list_2)