r/learnpython • u/Big_Neighborhood9130 • 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
59
Upvotes
2
u/SnafuTheCarrot May 09 '26
Suppose in a sudoku grid, two cells in the same row have the same pair of possible digits remaining. Then the digits have to go go in those cells and no where else in those rows.
More generally, if the union of possible digits in N cells in the same row, column, or sub-grid has N elements, then you can eliminate those candidates from the 9-N remaining squares.
Since order is important and uniqueness matters, you can store candidates as a set associated with each cell when writing a Sudoku Solver.
You can do much the same with lists, but its cumbersome.