How to make a list of lists in Python when it has multiple separators?
<p>The sample file looks like this (all on one line, wrapped for legibility):</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 of lists (as below) and replace "-" with Z (again, all on one line; wrapped here for legibility):</p>

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

<p>Here is a variation of Moses Koledoye's answer which examines the first character for <code>&gt;</code> and discards any matches as well as any empty elements.  I also included replacing "-" with "Z".</p>

<pre><code>lst = ['&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']

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

<p>This avoids assigning any particular significance to the length of any element.</p>

python list readfile strip