How to align two lists according to an arbitrary criterion?
<p>lets say I have two lists of persons, <code>persons_a</code> and <code>persons_b</code>. And I want to try to match each person in list <code>persons_a</code> with a person in <code>persons_b</code> according to an arbitrary attribute, for example <code>person.age</code>, <code>person.town_from</code> or so.</p>

<p>How could I do that in Python in a most efficient way?
Do I just do a for-loop?</p>

<pre><code>criteria = lambda a, b: a.age == b.age

result = []
for a in persons_a:
    for b in persons_b:
        if critera(a, b):
           result.add(a)
</code></pre>
