You are viewing a single comment's thread. Return to all comments →
import collections
n = int(input()) odi = collections.OrderedDict()
for word in range(n): word = input() odi[word] = odi.setdefault(word, 0) + 1
print(len(odi)) print(*list(odi.values()))
This was using OrderedDict and setdefault()
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Word Order
You are viewing a single comment's thread. Return to all comments →
import collections
n = int(input()) odi = collections.OrderedDict()
for word in range(n): word = input() odi[word] = odi.setdefault(word, 0) + 1
print(len(odi)) print(*list(odi.values()))
This was using OrderedDict and setdefault()