Build a word counter
Take your time, follow the code and check your understanding.
Move blocks into orderDictionaries
print(counts["code"])
counts[word] = counts.get(word, 0) + 1
for word in "code code".split():
counts = {}
Your answer3 min · no timer
Drag blocks, or use the arrow buttons. Keep the displayed indentation. This task uses the taught sequence; other equivalent programs may also be valid.
Show solution and explanation
Create the dictionary before using it. The indented statement belongs to the loop.
counts = {}
for word in "code code".split():
counts[word] = counts.get(word, 0) + 1
print(counts["code"])