In the following code.
>>> hash('bar')
327024216814240868
>>> hash('baz')
327024216814240876
>>> hash('bar') % 8
4
>>> hash('baz') % 8
4
bar
and baz
, however, have hash values that are exactly 8 apart and thus map to the exact same slot, 4
:
Their order now depends on which key was slotted first; the second key will have to be moved to a next slot:
>>> {'baz': None, 'bar': None}
{'bar': None, 'baz': None}
>>> {'bar': None, 'baz': None}
{'baz': None, 'bar': None}
But here both the outputs must be same as hash value of bar
comes before than baz
.
I meant,
>>>{'bar': None, 'baz': None}
should come,
{'bar': None, 'baz': None}