title: Python generator expression if-else
body: <p>I am using Python to parse a large file. What I want to do is</p>
  
  <pre><code>If condition =True
     append to list A
  else 
     append to list B
  </code></pre>
  
  <p>I want to use generator expressions for this - to save memory. I am putting in the actual code.</p>
  
  <pre><code>def is_low_qual(read):
      lowqual_bp=(bq for bq in phred_quals(read) if bq &lt; qual_threshold)  
      if iter_length(lowqual_bp) &gt;  num_allowed:
          return True
      else:
          return False  
  
  lowqual=(read for read in SeqIO.parse(r_file,"fastq") if is_low_qual(read)==True)
  highqual=(read for read in SeqIO.parse(r_file,"fastq") if is_low_qual(read)==False)
  
  
  SeqIO.write(highqual,flt_out_handle,"fastq")
  SeqIO.write(lowqual,junk_out_handle,"fastq")
  
  def iter_length(the_gen):
      return sum(1 for i in the_gen)
  </code></pre>