Question: In Python , write a function called count_characters() that counts the number of times each character appears in a user-supplied string s . Your function
In Python, write a function called count_characters() that counts the number of times each character appears in a user-supplied string s. Your function should loop over each element of the string, and sequentually update a dict whose keys are characters and whose values are the number of occurrences seen so far. You may know of other ways to achieve the same result. However, you should use this approach: for i in range(len(s)): instead.
Example usage and output:
count_characters("tortoise") {'t' : 2, 'o' : 2, 'r' : 1, 'i' : 1, 's' : 1, 'e' : 1}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
