我必须列出,其中有一些共同的元素:
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]]
我试图比较它们并找到共同的元素,然后对结果做一些工作:
do_job('target1/d/b/c', 'target1', 123, 334, 'link1/d/b/c')
现在我使用简单且非常慢的算法:
for item in p:
link = item[0]
target = item[1]
for item2 in q:
target2 = item2[0]
if target2 == target:
do_some_job(...)
我认为,我需要比较这两个列表并创建一个包含所有元素的列表,例如:
pq = [['target1/d/b/c', 'target1', 123, 334, 'link1/d/b/c'], ..., ['targetn/b/b/f', 'targetn', 23, 64, 'linkn/b/b/f']]
然后do_some_job(pq)
每次找到相同元素时调用而不是调用它
如何获得它?
此致