HW 12

Write a program charcount.py using the sample code below as a starter. Define the function charcount(str) that takes a single string as an argument. Your function will then count all occurrences of all unique characters in that string, saving them in a dictionary where the keys are characters and the values are their counts. Your function should return that dictionary.

REMINDER: a string is a sequence (like a list), so you can loop over its characters with a for loop.

# Your function definition here.



# Do not change this.
counts = charcount("ssss this is a short sentence")
print( counts['s'] )     # prints 8
print( counts['a'] )     # prints 1

Submit

Submit your charcount.py to the online submission system under hw13-chars.

submit -c=sd211 -p=hw13-chars charcount.py