【发布时间】:2020-05-25 00:02:13
【问题描述】:
filtradas 大约有 500000 个元素,_13 大约有 2000000 个元素,我使用 cython 达到的最短时间是 4 小时,但我需要在不到一个小时的时间内完成,我该怎么做?
两个列表都有带 1、2 或 X 的字符串元素,X 可以更改为 3
for i in filtradas:
for x in _13:
aciertos=0
if i[0]==x[0]:
aciertos+=1
if i[1]==x[1]:
aciertos+=1
if i[2]==x[2]:
aciertos+=1
if i[3]==x[3]:
aciertos+=1
if i[4]==x[4]:
aciertos+=1
if i[5]==x[5]:
aciertos+=1
if i[6]==x[6]:
aciertos+=1
if i[7]==x[7]:
aciertos+=1
if i[8]==x[8]:
aciertos+=1
if i[9]==x[9]:
aciertos+=1
if i[10]==x[10]:
aciertos+=1
if i[11]==x[11]:
aciertos+=1
if i[12]==x[12]:
aciertos+=1
if i[13]==x[13]:
aciertos+=1
if aciertos>=nroaciertos:
filtradas13.append(i)
break
return filtradas13
【问题讨论】:
-
可以有重复吗?如果没有,您可以使用 set 对象。如果有重复,首先对两个数组进行排序,然后遍历两个列表可能会快得多。
-
你在linux上吗?多处理可能有助于分叉系统。
-
@tdelaney 感谢您的评论。我在 Windows 上使用 fx 8350
-
@BillLynch 感谢您的评论。我已经用 set 消除了两个列表中的重复项
-
您能否详细说明您的意思是X 可以替换为3?这是否意味着 X 可以替换为空字符串或字符串
'3'?
标签: python python-3.x list loops nested-loops