Advertisement
mengyuxin

meng.prettyCharCount.py

Dec 30th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # prettyCharCount.py
  2. import pprint
  3.  
  4. msg = 'It was a bright cold day in April, ' + \
  5.       'and the clocks were striking thirteen.'
  6. count = {}
  7. for char in msg:
  8.     count.setdefault(char, 0)
  9.     count[char] += 1
  10.  
  11. # Solution 1 for Pretty Print
  12. print('Solution 1: ')
  13. for k, v in count.items():
  14.     print(str(k) + ': ' + str(v))
  15.  
  16. # Solution 2 for Pretty Print
  17. print('Solution 2: ')
  18. pprint.pprint(count)
  19.  
  20. # Solution 3 for Pretty Print
  21. print('Solution 3: ')
  22. print(pprint.pformat(count)) #pprint.pformat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement