Skip to content

Instantly share code, notes, and snippets.

@begimai
Created September 29, 2019 15:56
Show Gist options
  • Save begimai/41e7f756042b007a7acd15ed39513ce6 to your computer and use it in GitHub Desktop.
Save begimai/41e7f756042b007a7acd15ed39513ce6 to your computer and use it in GitHub Desktop.
You are given words. Some words may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification.
my_dict = {}
num = int(input())
for x in range(num):
word = input()
if word in my_dict:
my_dict[word] += 1
else:
my_dict[word] = 1
print(len(my_dict))
for x, y in my_dict.items():
print(y, end=' ')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment