Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class Sample:
  2. def __init__(self):
  3. self.contents = {}
  4. def insert(self, item):
  5. self.contents[item] = self.contents.get(item, 0) + 1
  6. def erase_one(self, item):
  7. if item in self.contents:
  8. del self.contents[item]
  9. def erase_many(self, matchCriteria):
  10. tempDict = self.contents.copy()
  11. for currentItem in tempDict:
  12. if currentItem == matchCriteria:
  13. self.erase_one(currentItem)
  14. def list_items(self):
  15. for currentItem in self.contents:
  16. print currentItem
  17.  
  18. test = Sample()
  19. test.insert(1)
  20. test.insert(1)
  21. test.insert(2)
  22. test.erase_many(1)
  23. test.list_items()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement