From 40fb63a37b53e26185b004a86b170f6c4679312f Mon Sep 17 00:00:00 2001 From: Yash2rule <53874370+Yash2rule@users.noreply.github.com> Date: Thu, 8 Oct 2020 15:20:50 +0530 Subject: [PATCH] added character count python file This program counts the frequency of all the characters present in the message string --- Python/char_count.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Python/char_count.py diff --git a/Python/char_count.py b/Python/char_count.py new file mode 100644 index 00000000..cbe0c91f --- /dev/null +++ b/Python/char_count.py @@ -0,0 +1,15 @@ +#character count game +import pprint +message='An apple a day keeps a doctor away' +count={} + +for character in message.upper(): + count.setdefault(character,0) + count[character]=count[character]+1 + +print(count) +#or +#pprint.pprint(count)#pprint stands for 'pretty print' +#or +#text=pprint.pformat(count) +#print(text)