some simple algorithms and data structures designing good hash functions is surprisingly challenging the problem is that one wants the outputs to be uniformly distributed given the expected distribution of inputs supposefor examplethat one hashed surnames by performing some calculation on the first three letters in the netherlandswhere roughly of surnames begin with "vanand another with "de,the distribution would be far from uniform figure uses simple hash function (recall that % returns the remainder when the integer is divided by the integer jto implement dictionary with integers as keys the basic idea is to represent an instance of class intdict by list of hash bucketswhere each bucket is list of key/value pairs by making each bucket listwe handle collisions by storing all of the values that hash to the same bucket in the list the hash table works as followsthe instance variable buckets is initialized to list of numbuckets empty lists to store or look up an entry with key dictkeywe use the hash function to convert dictkey into an integerand use that integer to index into buckets to find the hash bucket associated with dictkey we then search that bucket (which is listlinearly to see if there is an entry with the key dictkey if we are doing lookup and there is an entry with the keywe simply return the value stored with that key if there is no entry with that keywe return none if value is to be storedthen we either replace the value in the existing entryif one was foundor append new entry to the bucket if none was found there are many other ways to handle collisionssome considerably more efficient than using lists but this is probably the simplest mechanismand it works fine if the hash table is big enough and the hash function provides good enough approximation to uniform distribution notice that the __str__ method produces representation of dictionary that is unrelated to the order in which elements were added to itbut is instead ordered by the values to which the keys happen to hash this explains why we can' predict the order of the keys in an object of type dict