Write a function with signature: charcount(text) This should return a dictionary with 28 keys, "a", "b", ..., "z", plus "whitespace" and "others". For every lower-cased character in text, if the...



Write a function with signature:


charcount(text)


This should return a dictionary with 28 keys, "a", "b", ..., "z", plus "whitespace"


and "others". For every lower-cased character in text, if the character is


alphabetic increment the corresponding key; if the character is whitespace,


increment the "whitespace" key; otherwise increment the "others" key. For


example, the call


stats = charcount("Exceedingly Edible")


will mean that stats is a dictionary with the following contents:


{'whitespace': 1, 'others': 0, 'a': 0, 'c': 1, 'b': 1, 'e': 5,


'd': 2, 'g': 1, 'f': 0, 'i': 2, 'h': 0, 'k': 0, 'j': 0, 'm': 0,


'l': 2, 'o': 0, 'n': 1, 'q': 0, 'p': 0, 's': 0, 'r': 0, 'u': 0,


't': 0, 'w': 0, 'v': 0, 'y': 1, 'x': 1, 'z': 0}


Using a dictionary and a for loop, it can be done in just over a dozen lines of


code.



May 26, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here