title: Add to dictionary and count strings in a file based on specific conditions
body: <p>The program that I'm trying to make is supposed to take a file (dummy file for example, stream.txt):</p>
  
  <pre><code>andrew I hate mondays.
  fred Python is cool.
  fred Ko Ko Bop Ko Ko Bop Ko Ko Bop for ever
  andrew @fred no it isn't, what do you think @john???
  judy @fred enough with the k-pop
  judy RT @fred Python is cool.
  andrew RT @judy @fred enough with the k pop
  george RT @fred Python is cool.
  andrew DM @john Oops
  john DM @andrew Who are you go away! Do you know him, @judy?
  </code></pre>
  
  <p>and print the top <em>n</em> users with the most retweeted tweets. The first word in a given line is the user and everything else is the contents of a message, where 'RT' indicates a retweet, and 'DM' indicates a direct message.</p>
  
  <p>The program should print the user with the most retweets (<strong>not the user that retweets the most</strong>) next to the number of retweets that user has accumulated.</p>
  
  <p>n should be based on the number of users, which means if there is a tie there will be less than n lines printed as there will be two users with the same number value. The solution for the dummy data above would be as follows:</p>
  
  <pre><code>Enter n: 10
  2 fred
  1 judy
  </code></pre>
  
  <p>The code that I currently have is:</p>
  
  <pre><code>#define libraries used, counter, dictionary, and file path
  from collections import Counter, defaultdict
  from pathlib import Path
  
  def main():
      #define n as user input, can only be an integer
      n = input('Enter n: ')
      try:
          n = int(n)
      except:
          print('Invalid input.')
          return
      #Open file from path, read line by line and remove whitespace characters
      ss = Path('stream.txt').read_text().strip().split('\n')
      #Count tweets and add to dictionary, strip spaces and tabs, separate tweets from retweets
      c = Counter([
          i.strip().split(' ', 1)[0] for i in ss
          if i.strip().split(' ', 2)[1] in ('RT @ ')
  
      ])
      d = defaultdict(list)
      #Formatting
      for k, v in c.most_common():
          d[v].append(k)
      print('\n'.join([f'{k} {" ".join(v)}' for k, v in list(d.items())[:n]]))
  
  #runs main
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>However this gives an output of:</p>
  
  <pre><code>Enter n: 10
  1 judy andrew george
  </code></pre>
  
  <p>I'm new to python and have no idea how to progress from this point. Any help would be greatly appreciated.</p>