Reference part of list item in loop
<p>I am trying to turn a txt file into a new txt file with specific formatting so i can put it straight onto a website.</p>

<p>I have created a list called stats of the items to go under the Statistics heading but am now trying to write the loop to tell it to format the text in a specific way and I'm getting invalid syntax errors.</p>

<p>Here is what I have so far..</p>

<pre><code>txt = open(html_file, 'a')
    txt.write('&lt;h5&gt;&lt;a href="http://www.learningplusuk.org/data/education-reform" target="_blank"&gt;&lt;strong&gt;Education Reform&lt;/strong&gt;&lt;/a&gt;&lt;/h5&gt;'
            '\n'
            '&lt;p&gt;All the latest information on qualification reform can be found via our website, in the âEducation Reformâ section.&lt;/p&gt;'
            '\n'
            '&lt;hr&gt;'
            '\n'
            '&lt;p&gt;Statistics and Data&lt;/p&gt;'
            '\n'
            '&lt;hr&gt;'
            '\n')
for i in stats:
    j,k = enumerate(stats.split("\t"))

txt.write('&lt;h5&gt;&lt;a href=/"'i.split("\t")[4]'" target="_blank"&gt;&lt;strong&gt;'i.split("\t")[1]'&lt;/strong&gt;&lt;/a&gt;&lt;/h5&gt;'
            '\n'
            '&lt;h5&gt;&lt;strong&gt;'i.split("\t")[2]'&lt;/strong&gt;&lt;/h5&gt;'
            '&lt;p&gt;'i.split("\t")[3]'&lt;br&gt;&lt;/p&gt;'
            '&lt;hr&gt;'
            '\n')
txt.close()
</code></pre>

<p>but it says the i.split is invalid syntax. Any suggestions?</p>

<p>Thanks!</p>

<p>Try to use the + operator when concatenating strings: <code>'&lt;h5&gt;&lt;a href=/"' + i.split("\t")[4] + '" target=...'</code></p>

python