title: Python, using dictionaries and sets to keep track of all occurences of a word
body: <p>I am trying to solve <a href="https://www.hackerrank.com/challenges/word-order/problem" rel="nofollow noreferrer">this</a> problem:</p>
  <blockquote>
  <p>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.</p>
  <p>Note: Each input line ends with a &quot;\n&quot; character.</p>
  <p>Input Format</p>
  <p>The first line contains the integer, n .</p>
  <p>The next n lines each contain a
  word.</p>
  <p>Output Format</p>
  <p>Output 2 lines. On the first line, output the number of distinct words
  from the input. On the second line, output the number of occurrences
  for each distinct word according to their appearance in the input.</p>
  </blockquote>
  <p>I have implemented a solution like this,</p>
  <pre><code># Enter your code here. Read input from STDIN. Print output to STDOUT
  
  n  = int(input())
  
  mySet = set()
  myDict = {}
  
  for i in range(n):
      inp = input()[:-1]
      if inp not in mySet:
          mySet.add(inp)
          myDict[inp] = 1
      else:
          myDict[inp] += 1
  
  print(len(mySet))
  # print(' '.join(list(map(str, myDict.values()))))
  print(*myDict.values())
  </code></pre>
  <p>My strategy is as follows:</p>
  <p>If the word is not in <strong>mySet</strong>, add it to the set and create a value-key pair on <strong>myDict</strong> with word as key and 1 as value.</p>
  <p>If the word is in the set already, then increment the value of that word in the dictionary.</p>
  <p>However, half of the test cases are successfull, but the rest are &quot;Wrong Answer&quot;. So, I wonder, can anybody point out what do I miss to add to this code?</p>