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
Reviewed by CodexRitik
on
March 24, 2020
Rating:
n
ReplyDeleteNot able to run. error
ReplyDeleteFile "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'
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.
DeleteFile "Solution.py", line 7
Deleteprint(*d.values())
^
SyntaxError: invalid syntax
File "Solution.py", line 7
ReplyDeleteprint(*d.values())
^
SyntaxError: invalid syntax