How to make a list in python when the input file has multiple separators?
<p>The sample file looks like this:</p>

<pre><code> ['&gt;1\n', 'TCCGGGGGTATC\n', '&gt;2\n', 'TCCGTGGGTATC\n',
  '&gt;3\n', 'TCCGTGGGTATC\n', '&gt;4\n', 'TCCGGGGGTATC\n',
  '&gt;5\n', 'TCCGTGGGTATC\n', '&gt;6\n', 'TCCGTGGGTATC\n',
  '&gt;7\n', 'TCCGTGGGTATC\n', '&gt;8\n', 'TCCGGGGGTATC\n','\n',
  '$$$\n', '\n',
  '&gt;B1\n', 'ATCGGGGGTATT\n', '&gt;B2\n', 'TT-GTGGGAATC\n',
  '&gt;3\n', 'TTCGTGGGAATC\n', '&gt;B4\n', 'TT-GTGGGTATC\n',
  '&gt;B5\n', 'TTCGTGGGTATT\n', '&gt;B6\n','TTCGGGGGTATC\n',
  '&gt;B7\n', 'TT-GTGGGTATC\n', '&gt;B8\n', 'TTCGGGGGAATC\n',
  '&gt;B9\n', 'TTCGGGGGTATC\n','&gt;B10\n', 'TTCGGGGGTATC\n',
  '&gt;B42\n', 'TT-GTGGGTATC\n']
</code></pre>

<p>The <code>$$$</code>  separates the two sets. I need to use <code>.strip</code> function and remove the <code>\n</code> and all the "headers". </p>

<p>I need to make a list (as below) and replace "-" with Z </p>

<pre><code>  [ 'TCCGGGGGTATC','TCCGTGGGTATC','TCCGTGGGTATC', 'TCCGGGGGTATC',
    'TCCGTGGGTATC','TCCGTGGGTATC','TCCGTGGGTATC', 'TCCGGGGGTATC',
    'ATCGGGGGTATT','TT-GTGGGAATC','TTCGTGGGAATC', 'TT-GTGGGTATC',
    'TTCGTGGGTATT','TTCGGGGGTATC','TT-GTGGGTATC', 'TTCGGGGGAATC',
    'TTCGGGGGTATC','TTCGGGGGTATC','TT-GTGGGTATC']
</code></pre>

<p>Here is the link to a code (<a href="http://stackoverflow.com/a/39965048/6820344">http://stackoverflow.com/a/39965048/6820344</a>), where a similar question was answered. I tried to modify the code to get the output mentioned above. However, I am unable to have the list without the "$$$". Also, I need a list, not a list of lists. </p>

<pre><code>seq_list = []
for x in lst:
    if x.startswith('&gt;'):
        seq_list.append([])
        continue
    x = x.strip()
    if x:
        seq_list[-1].append(x.replace("-", "Z"))
print(seq_list)
</code></pre>

<pre><code>input = ['&gt;1\n', 'TCCGGGGGTATC\n', '&gt;2\n', 'TCCGTGGGTATC\n',
        '&gt;3\n', 'TCCGTGGGTATC\n', '&gt;4\n', 'TCCGGGGGTATC\n',
        '&gt;5\n', 'TCCGTGGGTATC\n', '&gt;6\n', 'TCCGTGGGTATC\n',
        '&gt;7\n', 'TCCGTGGGTATC\n', '&gt;8\n', 'TCCGGGGGTATC\n', '\n',
        '$$$\n', '\n',
        '&gt;B1\n', 'ATCGGGGGTATT\n', '&gt;B2\n', 'TT-GTGGGAATC\n',
        '&gt;3\n', 'TTCGTGGGAATC\n', '&gt;B4\n', 'TT-GTGGGTATC\n',
        '&gt;B5\n', 'TTCGTGGGTATT\n', '&gt;B6\n', 'TTCGGGGGTATC\n',
        '&gt;B7\n', 'TT-GTGGGTATC\n', '&gt;B8\n', 'TTCGGGGGAATC\n',
        '&gt;B9\n', 'TTCGGGGGTATC\n', '&gt;B10\n', 'TTCGGGGGTATC\n',
        '&gt;B42\n', 'TT-GTGGGTATC\n']

output = []

for elem in input:
    if elem.startswith('&gt;') or \
       elem.startswith('$') or \
       elem.isspace():
         continue

    output.append(elem.replace('-', 'Z').strip())

from pprint import pprint
pprint(output, compact=True)
</code></pre>

<p>When the preceding code is run, the following output is the result:</p>

<pre><code>['TCCGGGGGTATC', 'TCCGTGGGTATC', 'TCCGTGGGTATC', 'TCCGGGGGTATC', 'TCCGTGGGTATC',
 'TCCGTGGGTATC', 'TCCGTGGGTATC', 'TCCGGGGGTATC', 'ATCGGGGGTATT', 'TTZGTGGGAATC',
 'TTCGTGGGAATC', 'TTZGTGGGTATC', 'TTCGTGGGTATT', 'TTCGGGGGTATC', 'TTZGTGGGTATC',
 'TTCGGGGGAATC', 'TTCGGGGGTATC', 'TTCGGGGGTATC', 'TTZGTGGGTATC']
</code></pre>

python list append