如何在文本中找到所有相同的单词?

编程入门 行业动态 更新时间:2024-10-27 12:28:17
本文介绍了如何在文本中找到所有相同的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在文本中找到所有相同的单词。 这样做最好的主意是什么? 我使用了string.find但它没有正确地工作。 假设我想在文中找到一个数字324 ''45 324 45324'' 只出现一次324字,但string.find()发现2 次出现(在45324中) 必须我用正则表达式吗? 感谢您的帮助 L.

解决方案

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

>我需要在文本中找到所有相同的单词。 ''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 ... @ gmailwrote:

在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, 谢谢你你的帮助。 它完美无缺,但我忘了说我还需要找到每个单词出现的 的位置。是否有可能 谢谢。 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]

>>>

- 正在建设中

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 2occurrences ( 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...@gmailwrote:

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 2occurrences ( 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

更多推荐

如何在文本中找到所有相同的单词?

本文发布于:2023-11-29 19:25:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   如何在   文本中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!