In this HackerRank Word Order problem solution, You are given n-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.

HackerRank Word Order in python problem solution

HackerRank Word Order in python problem solution

num=int(raw_input())

unique_wordlist=[]
unique_worddict={}

c=0
while c<num:
    word=raw_input().rstrip('\r')
    if word not in unique_worddict:
        unique_worddict[word]=0
        unique_wordlist.append(word)
    unique_worddict[word]+=1
    c+=1
    
tempstr=''
for word in unique_wordlist:
    tempstr+=str(unique_worddict[word])+' '
    
print len(unique_worddict)
print tempstr