Doubt in Optinal Question

I am not able ti understand the hash function…
I mean how can we check the las condtion where
list(table) == [('a',99),('b',34)],
because hash('a') > 'hash('b'). So, ‘a’ always comes after ‘b’…
Please tell me where i am wrong and also tell me if i am asking the right question or am i going in the wron direction.

99 isn’t a hash of ‘a’, and 34 isn’t a hash of ‘b’.

The answer depends on how you acquire an index (which hashing function you use - custom built or pythons built-in).

1 Like

I have implemented get_valid_index like this…
The last case is giving False
When i Digged deeper i found that hash('a') returns greater value than hash('b')
So, the key-value pair of ‘a’ is inserted after the key-value pair of ‘b’.

What Can I do to TACKLE this ???

Sorry I didn’t understand the first Line.
And i am using the in-built hash function to get hash values…

Actually, tested this a bit, and learned that hash() results differ between runs:

hash of 'a': 4481939788840664557, hash('a') % max_size: 3565
hash of 'b': 5206211075269882626, hash('b') % max_size: 770

hash of 'a': 1931782193602269043, hash('a') % max_size: 3955
hash of 'b': -4190295978397739658, hash('b') % max_size: 1398

hash of 'a': 5111666997821574153, hash('a') % max_size: 3081
hash of 'b': 3994030463480646839, hash('b') % max_size: 3255

So not necessarily hash('a') > hash('b')

The problem may arise when you get actual index. As you can see sometimes the index for key ‘a’ is bigger, sometimes smaller.
To solve it, just sort the table and then compare:

sorted(list(table), key=lambda k: k[0]) == [('a', 99), ('b', 34)]

Now i get it thanks for helping…
Now it’s just fine
also i found an article on stackOverflow…