小编meh*_*lue的帖子

如何在python中向后搜索?

我正在使用具有项1,项1a和项2的html文件。是否有一种方法可以向后搜索并找到项2之前的项1a?

例:

text= """ this is an example item 1a thanks for helping item 2 blah blah item 1a""" 
Run Code Online (Sandbox Code Playgroud)

html python

1
推荐指数
1
解决办法
1073
查看次数

我的for循环只会提供最后的结果,而不是所有结果

我试图使用分数比较两个文本之间的相似性.这是我的代码:

risk_list1_txt = []
scoreList = []
similarityDict = {}
theScore = 0
for text1 in risk_list1:
    similarityDict['FileName'] = text1
    theText1 = open(path1 + "\\" + text1).read().lower()
    for text2 in range(len(risk_list2)):
        theText2 = open(path2 + "\\" + risk_list2[text2]).read().lower()
        theScore = fuzz.token_set_ratio(theText1,theText2)
        similarityDict[risk_list2[text2]] = theScore
    outFile= open(fileDestDir,'w')
    outFile.write(str(theScore))
outFile.close()
Run Code Online (Sandbox Code Playgroud)

问题是我的outfile只给了我最后一次比较的分数,虽然我在risk_list1和risk_list2中有3个不同的文本文件.我无法让这个循环正常运行.

python for-loop fuzzy-comparison

0
推荐指数
1
解决办法
70
查看次数

标签 统计

python ×2

for-loop ×1

fuzzy-comparison ×1

html ×1