-2

How do I write the code in Python by using dict?

The MultiSet ADT:

init(self) -

add(item, m) - Add item to the multiset with multiplicity m . If no multiplicity is given, it should default to multiplicity = 1.

remove(item, m) - Remove m copies of item from the multiset. If fewer than m copies are in the multiset, it should just remove all of them.

mult(item) - return the multiplicity of item in the multiset. If item is not in the multiset, then return 0 .

contains(item, m) - Return True if item appears in the multiset with multiplicity at least m . Return False otherwise.

Milkxd
  • 11
  • 1
  • 5
  • 1
    Hi! Looking at your last few questions, they seem to be not actual questions but specifications, and you're hoping for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please [see here](http://stackoverflow.com/help/how-to-ask) to learn how to write effective questions. – DSM Mar 23 '17 at 03:11
  • 1
    Seems like you just need to create a wrapper around `collections.Counter` or even a dict with an int counter as its value elements, if you are not allowed to use Counter. – Paul Rooney Mar 23 '17 at 03:14
  • Have a look at the Counter class in collections, which is a standard part of the Python distribution. – Bill Bell Mar 23 '17 at 03:14

1 Answers1

0

I suggest use Counter from collections, and just record the frequency each unique element appears. No need not invent another wheel.

Chuancong Gao
  • 654
  • 5
  • 7