How to convert this comprehension to a for-loop in Python?
<pre><code>sample = [['CGG','ATT'],['GCGC','TAAA']]
base_counts = [[Counter(base) for base in sub] for sub in sample]
#Output : [[Counter({'G': 2, 'C': 1}), Counter({'T': 2, 'A': 1})], [Counter({'C': 2, 'G': 2}), Counter({'A': 3, 'T': 1})]]

base_freqs = [[{k_v[0]:k_v[1]/len(bases[i]) for i,k_v in enumerate(count.items())} for count in counts] for counts, bases in zip(base_counts, sample)]
#Output 2 [[{'C': 0.3333333333333333, 'G': 0.6666666666666666}, {'A': 0.3333333333333333, 'T': 0.6666666666666666}], [{'C': 0.5, 'G': 0.5}, {'A': 0.75, 'T': 0.25}]]
</code></pre>

<p>The sample is the input and the Output2 is the final output of the program. The program with base_freqs, computes the frequency of "bases" (bases = ATGC) in each pair of the sample.  The output provides the correct answer. However, I would like to see the code in a for-loop format than comprehensions. </p>

<p>This code has been originally taken from the answer posted <a href="http://stackoverflow.com/a/40076570/6820344">here</a></p>

<p>You can always translate a list comprehension such as</p>

<pre><code>ls = [&lt;EXPR&gt; for &lt;VARS&gt; in &lt;ITERABLE&gt; if &lt;CONDITIONAL&gt;]
</code></pre>

<p>to</p>

<pre><code>ls = []
for &lt;VARS&gt; in &lt;ITERABLE&gt;:
    if &lt;CONDITIONAL&gt;:
        ls.append(&lt;EXPR&gt;)
</code></pre>

<p>Multiple <code>for</code> clauses in the comprehension correspond to nested <code>for</code> loops in the translation, with the leftmost <code>for</code> clause corresponding to the outermost <code>for</code> loop. </p>

<p>Translations for generator, dict and set comprehensions are analogous.</p>

python for-loop for-comprehension