You are viewing a single comment's thread. Return to all comments →
from collections import Counter
n = int(input().strip()) words = [input().strip() for _ in range(n)]
words_count = Counter(words)
distinct = [] for w in words: if w not in distinct: distinct.append(w)
print(len(distinct))
for d in distinct: print(words_count[d], end=" ") print()
Seems like cookies are disabled on this browser, please enable them to open this website
Word Order
You are viewing a single comment's thread. Return to all comments →
from collections import Counter
n = int(input().strip()) words = [input().strip() for _ in range(n)]
words_count = Counter(words)
distinct = [] for w in words: if w not in distinct: distinct.append(w)
print(len(distinct))
for d in distinct: print(words_count[d], end=" ") print()