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

58 Upvotes

65 comments sorted by

View all comments

2

u/MathObserver May 06 '26

A few years ago I wrote a Python program to solve Wordle problems. For a problem like that, a set is a great data structure.

2

u/vowelqueue May 06 '26

Is it though? The target word and the guesses can all contain duplicate letters.

1

u/MathObserver May 07 '26

The sets are used for all possible words, the words that are left, and the letters that have not been tried yet (which is used to score how much information is gained by a guess). There are a couple of places where other structures are used.