小编Net*_*ooc的帖子

计算包含单词的行

我有一个多行的文件。我想知道,对于整个文件中出现的每个单词,有多少行包含该单词,例如:

0 hello world the man is world
1 this is the world
2 a different man is the possible one
Run Code Online (Sandbox Code Playgroud)

我期待的结果是:

0:1
1:1
2:1
a:1
different:1
hello:1
is:3
man:2
one:1
possible:1
the:3
this:1
world:2
Run Code Online (Sandbox Code Playgroud)

请注意,“world”的计数是 2,而不是 3,因为该词出现在 2 行上。因此,将空白转换为换行符并不是正确的解决方案。

text-processing

7
推荐指数
2
解决办法
1099
查看次数

标签 统计

text-processing ×1