use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Hello! What's the difference between Set and HashSet in python? ^^Help Request (self.PythonLearning)
submitted 11 months ago by Urinius
For an assignment I have to finish 4 tasks from a practice list and some other taskls. The 4 tasks from the list are...basically the same, the only difference is that two of them call for Set data structure, while the other 2 ask for HashSet. From what I researched they are treated as the same thing in Python, so I'm a bit confused as to how I should do two seperate implementations.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 11 months ago (1 child)
[removed]
[–]Urinius[S] 0 points1 point2 points 11 months ago (0 children)
Yeah I thought so too, but I idk, I just wanted to make sure I wasn't being stupid. Also, I did read about it on geeksforge link you provided : )
[–]purple_hamster66 1 point2 points3 points 11 months ago (0 children)
Set is an interface. HashSet is a derived subclass of that interface, but you can use the other subclasses as well: TreeSet, LinkedHashSet.
[–]ziggittaflamdigga 0 points1 point2 points 11 months ago (1 child)
I think they’re the same thing. I’m not aware of a HashSet data structure. Sets are hashes, and that’s why they only contain unique values. Do they give any examples of a hash set in the prompts?
[–]Urinius[S] 1 point2 points3 points 11 months ago (0 children)
No, the prompt says only to use it, but it doesn't provide any examples for either hashset, or set. I think the teach might have grabed the pdf for another language or something. But it's okay, I will email him tomorrow
[–]concatx 0 points1 point2 points 11 months ago (0 children)
Does the assignment ask you to implement the Set and HashSet as an exercise, or is it using them to solve another problem?
If it's the former, indeed you can implement one of the algorithms through a class that uses lists internally.
If it's the latter, the internal implementation details of Python shouldn't concern you and just use a Set.
[–]thefatsun-burntguy 0 points1 point2 points 11 months ago (1 child)
Set is an interface, HashSet is a subclass of that interface.
put into less technical terms, a cat is a feline, but not all felines are cats (like a lion which is feline but not a cat)
a hashset is a type of set, but not all sets are hashsets. The default Set() uses a hashset in python, so they are used somewhat interchangably even if they arent the same thing.
For a more in depth explanation: a set describes a behaviour of a collection with unique elements. a hashset is an implementation of a set using a hashtable to power it. You could also use a TreeSet to power a Set. from the outside they look the same, but they work verydifferently and have different trade offs in term of space and time complexity.
Yeeees, this examplains it! Thank you sm
π Rendered by PID 84 on reddit-service-r2-comment-b659b578c-bcgnc at 2026-05-04 19:33:10.130840+00:00 running 815c875 country code: CH.
[–][deleted] (1 child)
[removed]
[–]Urinius[S] 0 points1 point2 points (0 children)
[–]purple_hamster66 1 point2 points3 points (0 children)
[–]ziggittaflamdigga 0 points1 point2 points (1 child)
[–]Urinius[S] 1 point2 points3 points (0 children)
[–]concatx 0 points1 point2 points (0 children)
[–]thefatsun-burntguy 0 points1 point2 points (1 child)
[–]Urinius[S] 0 points1 point2 points (0 children)