Question: Question 3: Implementing a History Dictionary In this question, you have to implement a dictionary that keeps the history of values that have been associated

 Question 3: Implementing a History Dictionary In this question, you have

to implement a dictionary that keeps the history of values that have

Question 3: Implementing a History Dictionary In this question, you have to implement a dictionary that keeps the history of values that have been associated with each key. You initialize the dictionary via: d - HDict() then you can update it via: d['cat'] = 4 d['dog'] = 6 d['cat'] = 32 # This updates what was assigned to the key 'cat' and you can retrieve the histories for each key via: d.history('cat') which yields the list of values assigned to key 'cat' in chronological order: [4, 32] and d.history('dog'), which yields simply [6] as the key 'dog' was only assigned to value 6. To implement this, you might want to look at the book chapter on classes, and specifically, at the timestapmed dictionary example. In implementing it, you can assume that one never passes anything to the initializer. My implementation consists of 10 lines of code. 1 class HDict(object): 2 3 ### YOUR CODE HERE I] 1 # This is a place where you can write additional tests to help you test 2 # your code, or debugging code, if you need. You can also leave it blank. 3 4 ### YOUR CODE HERE Here are some tests Here are some tests. [120] 1 ### 10 points: remembering the values. 2 3 d - HDict() 4 di..cat han 5 check_equal(d['cat'], 4) 6 d["dog'] = 5 7 check_equal(d[ 'dog'], 5) 8 check_equal(d['cat'], 4) 9 d['cat'] = 6 10 check_equal(d[ 'dog'], 5) 11 check_equal(d['cat'), 6) 12 [86] 1 ## 10 points: remembering history. 2 3 d = HDict() 4 dlication 5 d['dog'] = 5 6 d['cat'] = 6 7 check_equal(d.history('dog'), [5]) 8 check_equal(d.history('cat'), (4, 6]) 9

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!