title: List comprehension in python with variable assignment
body: <p>Suppose i have the following for loop </p>
  
  <pre><code>L=[]
  for e in C:
      t=0
      for r in D:
          if r[0]==e:
              t=t+r[2]
      L.append((e,t))
  </code></pre>
  
  <p>To give some more information e is a list, r is a tuple of size 3. I also want each element of L to contain a tuple. </p>
  
  <p>How do i write the following in a list comprehension? I'm unsure as there are variable assignments in the for loop. I'd really appreciate any help! Thanks!!</p>