← Back to Question List
Python Code Walkthrough #40
Counting Words With A Dict
📄 Code
Read carefully — what does this print?1counts: dict[str, int] = {}2for word in ['red', 'blue', 'red', 'green', 'red']:3 if word in counts:4 counts[word] = counts[word] + 15 else:6 counts[word] = 17print(counts)8print(counts['red'])