I have looked at many other posts such as How is set() implemented? and What does hash do in python? and I would like some clarification of my understanding. So far sets use a hashtable, with the key as a member of the set. So lets say I had
set1 = {'s','t','v'}
's' in set1
returns true, but how this is done to my understanding everything in set1 has had a hash, so for example the dictionary could be dict['s'] = true
, and to see if 's' in set1 is like checking dict['s']
and seeing if it is true or not. But my confusion comes from the fact that 's'
will always have the same hash, which means if I had 2 sets, if set1
hashed 's'
to being true, how does set2
hash 's'
differently? Does every set have its own special hash function?
set1 = {'s','t'}
print('x' in set1)
print('s' in set1)
set2 = {'s'}
print('s' in set2)
Does set2
and set1
have different hashes for 's'
when they are using the key as 's'
.