You are viewing a single comment's thread. Return to all comments →
First tried a few loops, worked but slow so didn't pass:
words = [input() for i in range(0, int(input()))] wordsset = set(words) def count(words, searchterm): return str(len([i for i in words if i == searchterm])) print(len(wordsset)) counts = [count(words,i) for i in wordsset] print(" ".join(counts))
So did a one pass attempt which works and passed:
dict = {} for i in range(0, int(input())): strin = input() count = dict.get(strin, 0) dict[strin] = count+1 print(len(dict)) print(' '.join(map(str, dict.values())))
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 →
First tried a few loops, worked but slow so didn't pass:
So did a one pass attempt which works and passed: