擅长:python、mysql、java
<p>我认为您不需要返回<code>list</code>。你可以这样做:</p>
<pre><code>def reduceOutputListToPossibleMatches(outputList, detailsList):
for outputItem in outputList:
isFound = False
for detailsItem in detailsList:
if detailsItem[14] == outputItem[4]: #there was a syntax error here
if isfound:
detailsItem[30] = "1"
break
isFound = True
else:
yield detailsItem
res = reduceOutputListToPossibleMatches(outputList, detailsList)
with open('somefile', 'w') as f:
f.writelines(res)
</code></pre>
<p>但它仍然是<code>O(n**2)</code>,速度相当慢。也许是一个SQL数据库(通过Django?)会更适合这个任务。在</p>
<p>对@Duncan建议的小改动:</p>
^{pr2}$