减少python代码的执行时间

2024-05-23 20:10:25 发布

您现在位置:Python中文网/ 问答频道 /正文

如何减少此代码的执行时间:

tab\u voyelle是一个包含2669433个不同单词的表格

for elem in tab_voyelle:
 words_match = []
 elem = elem.strip()
 Tab_elem_out = CheckImpli(elem,tab_voyelle)
if len(Tab_elem_out) != 0:
 MonFichINImpli = open('/home/user/Bureau/MesTravaux/MatchingCorpus/in_imply_result.txt','w')
 for i in range(len(Tab_elem_out)):
  MonFichINImpli.write(elem + ' ' + Tab_elem_out[i] + '\n')
  MonFichINImpli.close()
  subprocess.call(['java', '-jar', '/home/user/Bureau/MesTravaux/MatchingCorpus/dist/ImpliMorphVer4.jar','-i', 'in_imply_result.txt','-o','Result_Impli.txt'])
words_match = MatchingArabicWords('Result_Impli.txt','in_imply_result.txt')
if len(words_match) != 0 :
 MonFichierResultat.write('<mot id="'+elem+'">'+'\n')
 for valeur in words_match:
    valeur = valeur.strip()
    MonFichierResultat.write('<val>'+valeur+'</val>'+'\n')
    t = tab_voyelle[tab_voyelle.index(valeur)]
    del tab_voyelle[tab_voyelle.index(valeur)]
 MonFichierResultat.write('</mot>' + '\n')
if len(words_match) == 0:
 MonFichierResultat.write('<mot id="'+elem+'">'+'\n'+'<val></val>\n'+'</mot>' + '\n')
MonFichierResultat.write('</matching>' + '\n')
MonFichierResultat.close()

Tags: intxtlenmatchvalouttabwrite