class intdict(object)""" dictionary with integer keys""def __init__(selfnumbuckets)"""create an empty dictionary""self buckets [self numbuckets numbuckets for in range(numbuckets)self buckets append([]def addentry(selfdictkeydictval)"""assumes dictkey an int adds an entry ""hashbucket self buckets[dictkey%self numbucketsfor in range(len(hashbucket))if hashbucket[ ][ =dictkeyhashbucket[ (dictkeydictvalreturn hashbucket append((dictkeydictval)def getvalue(selfdictkey)"""assumes dictkey an int returns entry associated with the key dictkey""hashbucket self buckets[dictkey%self numbucketsfor in hashbucketif [ =dictkeyreturn [ return none def __str__(self)result '{for in self bucketsfor in bresult result str( [ ]':str( [ ]',return result[:- '}#result[:- omits the last comma figure implementing dictionaries using hashing the following code first constructs an intdict with twenty entries the values of the entries are the integers to the keys are chosen at random from integers in the range to (we discuss the random module in the code then goes on to print the intdict using the __str__ method defined in the class finally it prints the individual hash buckets by iterating over buckets (this is terrible violation of information hidingbut pedagogically useful import random # standard library module intdict( for in range( )#choose random int between and ** key random randint( ** addentry(keyiprint 'the value of the intdict is:print print '\ ''the buckets are:for hashbucket in buckets#violates abstraction barrier print 'hashbucket