List comprehension on Python dict doesn't perform well
<p>I have the following loop:</p>

<pre><code>for row in rows:
    print row.value('customer', 'name')
#   print [customer for customer in customers if customer['name'] == row.value('customer', 'name')]
</code></pre>

<p>When I uncomment the second <code>print</code>, the loop runs much more slowly. Is there a way I can write this to make it perform faster?</p>

<p>My overall problem is that I used to do a separate SQL query for each <code>row</code> to get the matching customer for that row. Now I'm trying to grab all the customers up front in an effort to improve performance.</p>

<p>One row of <code>customers</code> looks like this, FYI:</p>

<pre><code>{'name': u'JOHN SMITH', 'created_at': datetime.datetime(2010, 12, 1, 14, 49, 57), 'updated_at': datetime.datetime(2011, 3, 3, 16, 41, 1), 'customer_number': u'C102340', 'phone': u'', 'social_security_number': u'2352352', 'do_not_mail': None, 'id': 4154L, 'deceased': None}
</code></pre>
