小编Pie*_*ale的帖子

在多个文件中搜索单词的最有效方法

为了我的硕士论文,我下载了大量与金融相关的文件。我的目标是找到一组特定的词语(“第11章”)来标记所有已完成债务重组过程的公司。问题是我有超过 120 万个小文件,这使得搜索效率很低。现在我编写了非常基本的代码,并且达到了每 40-50 秒 1000 个文档的速度。我想知道是否有一些特定的库或方法(甚至编程语言)可以更快地搜索。这是我到目前为止使用的功能

def get_items(m):
    word = "chapter 11"
    f = open(m, encoding='utf8')
    document = f.read()
    f.close()
    return (word in document.lower())
# apply the function to the list of names:
l_v1 = list(map(get_items,filenames))
Run Code Online (Sandbox Code Playgroud)

文件大小在 5 到 4000 KB 之间变化

python string performance search file

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

标签 统计

file ×1

performance ×1

python ×1

search ×1

string ×1