t901.py 668 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import collections
  2. print collections.Counter()
  3. print collections.Counter('gallahad')
  4. c = collections.Counter({'red': 4, 'blue': 2})
  5. print c
  6. print c['green']
  7. print c
  8. c['green'] = 0
  9. print c
  10. print
  11. print
  12. x = collections.Counter('hello world!')
  13. print x
  14. for i in 'hello universe!':
  15. x[i] += 1
  16. print x
  17. l = list(x.elements())
  18. l.sort()
  19. print l
  20. print x.most_common(2)
  21. print x.most_common()
  22. a = collections.Counter({1:6, 2:4, 3:3})
  23. print a
  24. a.subtract({1:5, 2:-2, 4:7})
  25. print a
  26. a.subtract([1, 1])
  27. print a
  28. a.subtract(collections.Counter({1:-8, 3:2}))
  29. print a
  30. a.update({1:5, 2:-2, 4:7})
  31. print a
  32. a.update([1, 1])
  33. print a
  34. a.update(collections.Counter({1:-8, 3:2}))
  35. print a