def reduceOutputListToPossibleMatches(outputList, detailsList):
    details = {}
for detailsItem in detailsList:
    key = detailsItem[14]
if key in details:
    details[key][30] = '1'
else:
    details[key] = detailsItem
for outputItem in outputList:
    key = outputItem[4]
if key in details:
    yield details[key]
res = reduceOutputListToPossibleMatches(outputList, detailsList)
with open('somefile', 'w') as f:
    f.writelines(res)
Can Lists cope with a million items?