为了详细了解,我附上了一个文件链接: Actual file
我在列表中有类似语法的数据,如:
i = [a.b>c.d , e.f.g>h.i.j ]
例如,列表中的每个元素都有多个子元素,以“.”和“>;”分隔
for i in range(0, len(l)):
reac={}
reag={}
t = l[i].split(">")
REAC = t[0]
Reac = REAC.split(".")
for o in range(len(Reac)):
reaco = "https://ai.chemistryinthecloud.com/smilies/" + Reac[o]
respo = requests.get(reaco)
reac[o] ={"Smile":Reac[o],"Details" :respo.json()}
if (len(t) != 1):
REAG = t[1]
Reag = REAG.split(".")
for k in range(len(Reag)):
reagk = "https://ai.chemistryinthecloud.com/smilies/" + Reag[k]
repo = requests.get(reagk)
reag[k] = {"Smile": Reag[k], "Details" :repo.json()}
res = {"Reactants": list(reac.values()), "Reagents": list(reag.values())}
boo.append(res)
else:
res = {"Reactants": list(reac.values()), "Reagents": "No reagents"}
boo.append(res)
我们已经分离了所有元素,对于每个元素,我们调用第三方API。那会消耗太多的时间
是否有任何方法可以减少此时间并优化循环
回复大约需要1分钟。我们希望优化到5-10秒
就这么做吧。我更改了输出的格式,因为它使事情变得不必要的复杂,并删除了许多您正在做的非Python的事情。第二次运行应该是瞬时的,如果在方程式或反应侧面有重复值,第一次应该快得多
相关问题 更多 >
编程相关推荐