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())




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube