title: Python append a string after an occurrence of a pattern
body: <p>How do I append to a string after an occurrence of a pattern?? I know that strings are immutable. But if there is a way to do it?</p>
  
  <p>Eg..
  input:</p>
  
  <pre><code>condor  t   airline airline
  eight   n   0   flightnumber
  nine    n   0   flightnumber
  five    n   0   flightnumber
  hallo   t   0   sentence
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>&lt;s&gt; &lt;callsign&gt; &lt;airline&gt; condor &lt;/airline&gt; 
  &lt;flightnumber&gt; eight nine five &lt;/flightnumber&gt; 
  &lt;/callsign&gt; hallo &lt;/s&gt;
  </code></pre>
  
  <p>Program:</p>
  
  <pre><code>import re
  import string
  import csv
  out = ''
  with open('input.txt', 'r') as f:
    reader = csv.reader(f, delimiter='\t')
    for row in reader:
      if (row == "\n"):
          out += "\n"
      if 'airline' in row:
          print '&lt;callsign&gt; &lt;airline&gt;' + row[0] + '&lt;/airline&gt;&lt;/callsign&gt;'
      if 'sentence' in row: 
          print '&lt;s&gt;' + row[0] + '&lt;/s&gt;'
      if 'flightnumber' in row: 
          print '&lt;flightnumber&gt;' + row[0] + '&lt;/flightnumber&gt;'
  </code></pre>
  
  <p>Produces:</p>
  
  <pre><code>&lt;callsign&gt; &lt;airline&gt;condor&lt;/airline&gt;&lt;/callsign&gt;
  &lt;flightnumber&gt;eight&lt;/flightnumber&gt;
  &lt;flightnumber&gt;nine&lt;/flightnumber&gt;
  &lt;flightnumber&gt;five&lt;/flightnumber&gt;
  &lt;s&gt;hallo&lt;/s&gt;
  </code></pre>
  
  <p>Is there a way that I can make this^ to the one in expected output?</p>