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())
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






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