Der Code, den ich unten habe, sollte die Anzahl der Wörter, die mit einem bestimmten Buchstaben beginnen, laufen lassen, aber wenn ich ihn benutze, sind die Zählungen alle 0, anstatt was sie sein sollten: {'I' : 2, 'b': 2, 't': 3, 'f': 1}. Ich schätze jede Hilfe. Vielen Dank!Code läuft nicht richtig
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))
Wörterbuch Verständnis ist richtig, was zu tun ist –