SyntaxFix
Write A Post
Hire A Developer
Questions
Without defaultdict:
words = "apple banana apple strawberry banana lemon" my_count = {} for word in words.split(): try: my_count[word] += 1 except KeyError: my_count[word] = 1