Open
Description
<Arrinao> sentence = input("Enter a sentence: ")
<Arrinao> counts = {}
<Arrinao> for word in sentence.split():
<Arrinao> counts[word] = counts.get(word, 0) + 1
<Akuli> two cases: word is not in counts, word is in counts
<Akuli> word not in counts: counts[word] = 0+1
<Akuli> s o when we see it for the first time, set count to 1
<Akuli> and when word is in counts, it does: counts[word] = counts[word] + 1
<Akuli> so when we see a word we already saw before, we increment the count
Metadata
Metadata
Assignees
Labels
No labels