title: Replacing nested for loops and value assignment for list comprehension
body: <p>I've written a function to count the occurences of certain characters (<code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>) within multiple strings at the same position and save the number of occurrences in a dictionary.</p>
  
  <p>For example with these two strings 'ACGG' and 'CAGT', it should return:</p>
  
  <pre><code>{'A': [1, 1, 0, 0], 'C': [1, 1, 0, 0], 'G': [0, 0, 2, 1], 'T': [0, 0, 0, 1]}
  </code></pre>
  
  <p>I want to convert the code below to list comprehension to optimize it for speed. It uses two nested for loops, and the input Motifs is a list of strings containing A's C's G's and T's.</p>
  
  <pre><code>def CountWithPseudocounts(Motifs):
      count = {}
      k = len(Motifs[0])
      t = len(Motifs)
      for s in 'ACGT':
          count[s] = [0] * k
      for i in range(t):
          for j in range(k):
              symbol = Motifs[i][j]
              count[symbol][j] += 1
  return count
  </code></pre>
  
  <p>I've tried replacing the nested for loops at the bottom of the function for this list comprehension:</p>
  
  <pre><code>count = [ [ count[Motifs[i][j]][j] += 1 ] for i in range(0, t) ] for j in range(0, k)]
  </code></pre>
  
  <p>It doesn't work, probably because I'm not allowed to do the value assignment of += 1 within the list comprehension. How can I work around this?</p>