title: Python: failed to write results in multiple files
body: <p>I have a master draft text file which has the tags like PA, ST etc. My intention is to create a file for each tag and write the lines containing the tag in to the corresponding file. Here is my current python code</p>
  
  <pre><code>#!/usr/bin/python3
  import sys
  flnmc=sys.argv[1]
  
  tags_dict={'PA':'Positive_Assertions','ST':'Self_improvement_Thought'\
  ,'TO':'TodO_task','WK':'WorK_todo','FN':'FuNny','CURRENT':'CURRENT'}
  
  print(flnmc)
  
  def grep_tags(tag):
    with open(flnmc,'r') as fc:
      for line in fc:
        if tag in line:
          print(line,end='')
  
  grep_tags('WK')
  
  fc=open(flnmc,'r')
  for tag, s in tags_dict.items():
    f=open("%s.txt" %s,'w')
    for line in fc:
      if tag in line:
        f.write(line)
    f.close()
  </code></pre>
  
  <p>Problems: grep_tags function is working fine printing the lines containing the tag of the master text file. Also all the required files are created. But when it comes to writing the grepped results to corresponding files, I found only first tag's results are written as required while other tag files are empty.</p>