아래 코드는 특정 문자로 시작하는 단어의 개수를 실행하도록되어 있지만 실행했을 때 개수는 0이어야합니다. { 'I' : 2, 'b': 2, 't': 3, 'f': 1}. 어떤 도움을 주셔서 감사합니다. 감사!코드가 제대로 실행되지 않습니다.
def initialLets(keyStr):
'''Return a dictionary in which each key is the initial letter of a word in t and the value is the number of words that begin with that letter. Upper
and lower case letters should be considered different letters.'''
inLets = {}
strList = keyStr.split()
firstLets = []
for words in strList:
if words[0] not in firstLets:
firstLets.append(words[0])
for lets in firstLets:
inLets[lets] = strList.count(lets)
return inLets
text = "I'm born to trouble I'm born to fate"
print(initialLets(text))
사전 이해가 옳은 일입니다. –