Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help with python please: Define a function count_starts(text). The text paramete

ID: 3577631 • Letter: H

Question

help with python please:

Define a function count_starts(text). The text parameter is a list of strings. The function should check the starting character of each string in the list, construct and return a dictionary that uses the leading characters of each string in text as keys and an integer number as their values to report how many strings start with that character. Assumption: all strings in the list are non-empty, but the list might be empty. Examples: count_starts(["merry", "Christmas", "happy", "holidays']) rightarrow {'m':1, 'C':1, 'h':2} count_starts(["time", "after", "time"]) rightarrow {'t': 2, 'a': 1} count_starts([]) rightarrow {} def count_starts(text):

Explanation / Answer

def count_starts(text):

dict = {}

for x in range(0, len(text)):

y = text[x]

if y[0] in dict.keys():

dict[y[0]] = 1

else:

dict[y[0]] = + 1

return dict

print count_starts(["merry","Christmas", "happy", "holidays"])