HackerRank Python - Word Order



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.



  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from collections import OrderedDict
  3. dict = OrderedDict()
  4. for _ in range(int(input())):
  5. key = input()
  6. dict[key] = dict.get(key, 0) + 1
  7. print(len(dict))
  8. print(*dict.values())

download android app