Word Order - Hackerrank Solution

 

Word Order


Objective


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.

Note: Each input line ends with a "\n" character


Solution:

from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
    pass
d = OrderedCounter(input() for _ in range(int(input())))
print(len(d))
print(*d.values())


Note:

This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

Word Order - Hackerrank Solution Word Order - Hackerrank Solution Reviewed by CodexRitik on March 24, 2020 Rating: 5

5 comments:

  1. Not able to run. error
    File "test.py", line 4, in \n
    d = OrderedCounter(input() for _ in range(int(input())))\n
    ValueError: invalid literal for int() with base 10: 'fer jht ght'

    ReplyDelete
    Replies
    1. Above Given Code is verified by all test cases so pls make sure write a correct code.Try again.if possible send me snapshot of that error.

      Delete
    2. File "Solution.py", line 7
      print(*d.values())
      ^
      SyntaxError: invalid syntax

      Delete
  2. File "Solution.py", line 7
    print(*d.values())
    ^
    SyntaxError: invalid syntax

    ReplyDelete

Powered by Blogger.