Pythonic proportion calculation of two conditions
<p>Here's a really simple question regarding pythonic coding.</p>

<p>Given a list, if you want to calculate the proportion of items satisfying (A and B), out of those satisfying (A), a natural solution would be:</p>

<p>Imagine the list is of integers, condition A is (>3), condition B is (>5)</p>

<pre><code>count = 0
correct = 0

for item in items:
  if item &gt; 3:
    count += 1

    if item &gt; 5:
      correct += 1

score = float(correct) / count
print '%.2f' % score
</code></pre>

<p>An alternative solution:</p>

<pre><code>count = len([1 for i in items if i &gt; 3])
correct = len([1 for i in items if i &gt; 5])

score = float(correct) / count
print '%.2f' % score
</code></pre>

<p>The alternative looks sexier to me, though it loops through items twice and is not efficient. Is there an accepted pythonic solution to this common scenario or is the first solution good enough?</p>

<p>Thanks.</p>
