How to find all the same words in a text?

ZeD vito.detullio at gmail.com
Sat Feb 10 09:07:19 EST 2007


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



More information about the Python-list mailing list