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

Pythin Question Write a function named initialDict that takes a string, text , a

ID: 3935872 • Letter: P

Question

Pythin Question

Write a function named initialDict that takes a string, text, as a parameter and computes and returns a dictionary in which each initial letter of a word in text is a key. All keys should be lower cased. The value of each key is a list of all words in text beginning with that letter.

Input: text, a string

Return:           a dictionary of initial letter:word list pairs

For example, the following would be correct output.

print(initialDict('The Call of the Wild'))

{'c': ['Call'], 't': ['The', 'the'], 'w': ['Wild'], 'o': ['of']}

Explanation / Answer

def initialDict(str):

new_str=str.split(" ")

for s in new_str:

print '''

print s[0],'':['

print s,','

for i in range(new_str.index(s),len(new_str)):

st=s.lower()

st1=new_str[i].lower()

if(st[0]==st1[0])

print new_str[i],','

new_str.remove(new_str[i])

print ']'

print ','