[Solved]Write Class Counter Class Inherits Dict Must Inherit Dict Counter Object Allows Count Obj Q37256373
python 3:

Write a class Counter class that inherits from dict (you MUST inherit from dict). A Counter object allows you to count objects as follows. The repr will display the objects counted along with the counts of each of them. (Note that the 1:2 means that the number 1 was counted twice). >>> CCounter () >>> C.count (1) >>> c. count (1 >>> C. count (3) >>> C.count (5) >>>c #callsrepr Counter (1: 2, 3: 1, 5: 1) – Individual counts can be retrieved by indexing into the Counter object. If an item has not been counted then a count of 0 is returned (rather than an error). Implement the getitem method to make this work: 2 1 There is also a countItems method that can count all the items in a list (by iterating through them and counting each): >>>C Counter () >>> C.countItems [3,1,2,1,3,2,3] ) Counter (3: 3, 1: 2, 2: 2)) There is also a method printCounts that prints out all the counts. Note that it will print the keys in sorted order. This is easily accomplished: instead of iterating over a dict d, one can iterate over sorted(d): >>> C.printCounts () Show transcribed image text Write a class Counter class that inherits from dict (you MUST inherit from dict). A Counter object allows you to count objects as follows. The repr will display the objects counted along with the counts of each of them. (Note that the 1:2 means that the number 1 was counted twice). >>> CCounter () >>> C.count (1) >>> c. count (1 >>> C. count (3) >>> C.count (5) >>>c #callsrepr Counter (1: 2, 3: 1, 5: 1) – Individual counts can be retrieved by indexing into the Counter object. If an item has not been counted then a count of 0 is returned (rather than an error). Implement the getitem method to make this work: 2 1 There is also a countItems method that can count all the items in a list (by iterating through them and counting each): >>>C Counter () >>> C.countItems [3,1,2,1,3,2,3] ) Counter (3: 3, 1: 2, 2: 2)) There is also a method printCounts that prints out all the counts. Note that it will print the keys in sorted order. This is easily accomplished: instead of iterating over a dict d, one can iterate over sorted(d): >>> C.printCounts ()
Expert Answer
Answer to Write a class Counter class that inherits from dict (you MUST inherit from dict). A Counter object allows you to count o… . . .
OR

