如何在文本中找到所有相同的单词? [英] How to find all the same words in a text?

查看:93
本文介绍了如何在文本中找到所有相同的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文本中找到所有相同的单词。

这样做最好的主意是什么?

我使用了string.find但它没有正确地工作。

假设我想在文中找到一个数字324


''45 324 45324''


只出现一次324字,但string.find()发现2

次出现(在45324中)


必须我用正则表达式吗?

感谢您的帮助

L.

解决方案

在2007年2月10日星期六上午05:29:23 -0800,Johny写道:


>我需要在文本中找到所有相同的单词。<这样做最好的想法是什么?
我使用了string.find,但它对单词不起作用。
假设我想在文本中找到一个数字324 />
''45 324 45324''

只出现了一个324字,但string.find()找到了2个字/>出现次数(也在45324中)


>>'' 45 324 45324''。split()。count(''324'')



1


>>>



ciao

marco


-

回复`python -c" print''m ******** @ itsuig.ocram''[:: - 1]"`


-----开始PGP SIGNATURE -----

版本:GnuPG v1.4.6(GNU / Linux)

iD8DBQFFzcu6mQRKGuVp5FMRArzTAKCpmT / ykP1K8HQaF30phLeq8zBUzQCfZCEU

6RA4kH2QdMe0wcm97MrUWfM =

= p9iU

----- END PGP SIGNATURE -----


2月10日下午2:42,Marco Giusti< marco.giu ... @ gmail.comwrote:


在2007年2月10日星期六上午05:29:23 -0800,Johny写道:


我需要在文本中找到所有相同的单词。

这样做最好的想法是什么?

我使用了string.find,但它对单词不起作用。

假设我想要在文本中找到一个数字324


''45 324 45324''


只出现一次324字,但string.find()找到2

次发生(在45324中)


>>'''45 324 45324''。split()。count(''324'')



1

< blockquote class =post_quotes>
>>>



ciao



Marco,

谢谢你你的帮助。

它完美无缺,但我忘了说我还需要找到每个单词出现的

的位置。是否有可能

谢谢。

L


Johny写道:


>假设我想在文本
中找到一个数字324


>''45 324 45324''


>只有一次出现324字,但string.find()发现2
发生(也在45324)


> >>''45 324 45324''。split()。count(''324'')


1


> >>>


ciao



Marco,

感谢您的帮助。

它运作完美但我忘了说我还需要找到每个单词出现的

的位置。是否有可能


>> [i for i,e in enumerate(''45 324 45324''。split())如果e ==''324'']



[1]

< blockquote class =post_quotes>


>>>



-

正在建设中


I need to find all the same words in a text .
What would be the best idea to do that?
I used string.find but it does not work properly for the words.
Let suppose I want to find a number 324 in the text

''45 324 45324''

there is only one occurrence of 324 word but string.find() finds 2
occurrences ( in 45324 too)

Must I use regex?
Thanks for help
L.

解决方案

On Sat, Feb 10, 2007 at 05:29:23AM -0800, Johny wrote:

>I need to find all the same words in a text .
What would be the best idea to do that?
I used string.find but it does not work properly for the words.
Let suppose I want to find a number 324 in the text

''45 324 45324''

there is only one occurrence of 324 word but string.find() finds 2
occurrences ( in 45324 too)

>>''45 324 45324''.split().count(''324'')

1

>>>

ciao
marco

--
reply to `python -c "print ''m********@itsuig.ocram''[::-1]"`

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFFzcu6mQRKGuVp5FMRArzTAKCpmT/ykP1K8HQaF30phLeq8zBUzQCfZCEU
6RA4kH2QdMe0wcm97MrUWfM=
=p9iU
-----END PGP SIGNATURE-----


On Feb 10, 2:42 pm, Marco Giusti <marco.giu...@gmail.comwrote:

On Sat, Feb 10, 2007 at 05:29:23AM -0800, Johny wrote:

I need to find all the same words in a text .
What would be the best idea to do that?
I used string.find but it does not work properly for the words.
Let suppose I want to find a number 324 in the text

''45 324 45324''

there is only one occurrence of 324 word but string.find() finds 2
occurrences ( in 45324 too)

>>''45 324 45324''.split().count(''324'')

1

>>>


ciao

Marco,
Thank you for your help.
It works perfectly but I forgot to say that I also need to find the
possition of each word''s occurrence.Is it possible that
Thanks.
L


Johny wrote:

>Let suppose I want to find a number 324 in the text

>''45 324 45324''

>there is only one occurrence of 324 word but string.find() finds 2
occurrences ( in 45324 too)

> >>''45 324 45324''.split().count(''324'')

1

> >>>


ciao

Marco,
Thank you for your help.
It works perfectly but I forgot to say that I also need to find the
possition of each word''s occurrence.Is it possible that

>>[i for i, e in enumerate(''45 324 45324''.split()) if e==''324'']

[1]

>>>

--
Under construction


这篇关于如何在文本中找到所有相同的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆