Advertisement
mengyuxin

meng.charCount.py

Dec 30th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. # charCount.py
  2. msg = 'It was a bright cold day in April, ' + \
  3.       'and the clocks were striking thirteen.'
  4. count = {}
  5. for char in msg:
  6.     count.setdefault(char, 0)
  7.     count[char] += 1
  8.  
  9. print(count)
  10. print('\nThe answer is :')
  11.  
  12. for k, v in count.items():
  13.     print(str(k) + ': ' + str(v))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement