title: Python: How can I add the line number of frequencies and sort alphabetically using dictionaries
body: <p>I have a project where I must obtain the amount of frequencies of each word through sys.stdin</p>
  
  <p>I have obtained that part. The second part is getting the line number for each word, I feel I have obtained that but I cannot add to the output string the line number and I also cant figure out a way to sort alphabetically if the word has the same frequency</p>
  
  <p>Here is my code:</p>
  
  <pre><code>if __name__ == '__main__':
  
  wordCount = defaultdict(list)
  words = {}
  
  for i, line in enumerate(sys.stdin.readlines()):
      wordCount[line].append(i+1) #add the line number to each element in the line
      for word in line.lower().split():
          words[word] = words.get(word, 0) + 1
  
  sortedList = sorted(words.items(), key=itemgetter(1), reverse=True)
  for word, frequency in sortedList:
      print("%d %s" % (frequency, word))," " # &lt;-- HERE I NEED TO ADD THE LINE NUMBER AND ALSO SORT ALPHABETICALLY
  </code></pre>
  
  <p>If I input "Python is really cool" #line 1
  "I am working with python really" #line 2</p>
  
  <p>Output should be:</p>
  
  <pre><code>2 python 1 2
  
  2 really 1 2
  
  1 am 2
  
  1 cool 1
  
  1 I 2
  
  1 is 1
  
  1 with 2
  
  1 working 2
  </code></pre>