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