algorithm to compare two lists and get same elements in python
<p>I have to lists, which has some common elements in them:</p>

<pre><code>p = [('link1/d/b/c', 'target1/d/b/c'), ('link2/a/g/c', 'target2/a/g/c'), ..., ('linkn/b/b/f', 'targetn/b/b/f')]

q = [['target1/d/b/c', 'target1', 123, 334], ['targetn/b/b/f', 'targetn', 23, 64], ... ,['targetx/f/f/f', 'targetx', 999, 888]]
</code></pre>

<p>Im trying to compare them and find common elements, and then do some job with result:</p>

<pre><code>do_job('target1/d/b/c', 'target1', 123, 334, 'link1/d/b/c')
</code></pre>

<p>for now im using simple and very slow alghortihm:</p>

<pre><code>for item in p:
   link = item[0]
   target = item[1]
   for item2 in q:
       target2 = item2[0]
       if target2 == target:
           do_some_job(...)
</code></pre>

<p>I thougth, that I need to compare this two lists and get create one list which will contain all elements, eg:</p>

<pre><code>pq = [['target1/d/b/c', 'target1', 123, 334, 'link1/d/b/c'], ..., ['targetn/b/b/f', 'targetn', 23, 64, 'linkn/b/b/f']]
</code></pre>

<p>and then call <code>do_some_job(pq)</code> instead of calling it each time when I found  same element</p>

<p>How to gain it ?</p>

<p>best regards</p>
