Question: First you need to implement the three methods that have pass right underneath the method. After you implement those methods you need to pass the

First you need to implement the three methods that have "pass" right underneath the method. After you implement those methods you need to pass the test. After you right the three test you might need to create your own methods to pass the other test. Implement a dictionary using chaining.  You may assume every key has a hash() method, e.g.:  >>> hash(1)  1 
import unittest ''' Description: Author: Version: Help provided to: Help received from: '''  '''  Implement a dictionary using chaining.  You may assume every key has a hash() method, e.g.:  >>> hash(1)  1  >>> hash('hello world')  -2324238377118044897 '''  class dictionary: def __init__(self, init=None): self.__limit = 10 self.__items = [[] for _ in range(self.__limit)] self.__count = 0 if init: for i in init: self.__setitem__(i[0], i[1]) def __len__(self): pass   def flattened(self): return [item for inner in self.__items for item in inner] def __iter__(self): return(iter(self.flattened())) def __str__(self): return(str(self.flattened())) def __setitem__(self, key, value): ''' Add to the dictionary. '''  pass   def __getitem__(self, key): ''' Retrieve from the dictionary. '''  pass   def __contains__(self, key): ''' Implements the 'in' operator. '''  pass  ''' C-level work '''  class test_add_two(unittest.TestCase): def test(self): s = dictionary() s[1] = "one"  s[2] = "two"  self.assertEqual(len(s), 2) self.assertEqual(s[1], "one") self.assertEqual(s[2], "two") ''' class test_add_twice(unittest.TestCase):  def test(self):  s = dictionary()  s[1] = "one"  s[1] = "one"  self.assertEqual(len(s), 1)  self.assertEqual(s[1], "one")  class test_store_false(unittest.TestCase):  def test(self):  s = dictionary()  s[1] = False  self.assertTrue(1 in s)  self.assertFalse(s[1])  class test_store_none(unittest.TestCase):  def test(self):  s = dictionary()  s[1] = None  self.assertTrue(1 in s)  self.assertEqual(s[1], None)  class test_none_key(unittest.TestCase):  def test(self):  s = dictionary()  s[None] = 1  self.assertTrue(None in s)  self.assertEqual(s[None], 1)  class test_False_key(unittest.TestCase):  def test(self):  s = dictionary()  s[False] = 1  self.assertTrue(False in s)  self.assertEqual(s[False], 1)  class test_collide(unittest.TestCase):  def test(self):  s = dictionary()  s[0] = "zero"  s[10] = "ten"  self.assertEqual(len(s), 2)  self.assertTrue(0 in s)  self.assertTrue(10 in s) '''  ''' B-level work  Add doubling and rehashing when load goes over 75%  Add __delitem__(self, key) '''  ''' A-level work  Add halving and rehashing when load goes below 25%  Add keys()  Add values() '''  ''' Extra credit  Add __eq__()  Add items(), "a list of D's (key, value) pairs, as 2-tuples" '''  if __name__ == '__main__':  unittest.main()
 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!