How to find all the same words in a text?
Samuel Karl Peterson
skpeterson at nospam.please.ucdavis.edu
Sun Feb 11 23:13:20 EST 2007
attn.steven.kuo at gmail.com on 11 Feb 2007 08:16:11 -0800 didst step
forth and proclaim thus:
> More concisely:
>
> import re
>
> pattern = re.compile(r'\b324\b')
> indices = [ match.start() for match in
> pattern.finditer(target_string) ]
> print "Indices", indices
> print "Count: ", len(indices)
>
Thank you, this is educational. I didn't realize that finditer
returned match objects instead of tuples.
> Cheers,
> Steven
>
--
Sam Peterson
skpeterson At nospam ucdavis.edu
"if programmers were paid to remove code instead of adding it,
software would be much better" -- unknown
More information about the Python-list
mailing list