How to find all the same words in a text?

Marco Giusti marco.giusti at gmail.com
Sat Feb 10 09:16:08 EST 2007


On Sat, Feb 10, 2007 at 06:00:05AM -0800, Johny wrote:
>On Feb 10, 2:42 pm, Marco Giusti <marco.giu... at gmail.com> wrote:
>> 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

    >>> li = '45  324 45324'.split()
    >>> li.index('324')
    1
    >>> 

play with count and index and take a look at the  help of both

ciao
marco

-- 
reply to `python -c "print 'moc.liamg at itsuig.ocram'[::-1]"`
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20070210/8ff4c84d/attachment.sig>


More information about the Python-list mailing list