Search substring in a string and get index of all occurances

Fredrik Lundh fredrik at
Wed Jun 21 14:01:34 CEST 2006

Maric Michaud wrote:

> Another variant, I feel this one more natural as it doesn't contain a
> C-looking infinite loop

doing things in a convoluted way because you think that non-infinite while-
loops are not natural?  you can get help for that, you know ;-)

> Actually it's even more efficient than Lundh's one for smaller strings (less
> than 1000 characters on my box) and slow down as strings go wider (slowly,
> seems to be a logarithmic progression) due to the split call resulting in
> creation of a new list.

and a potentially large number of new strings.  there's a lot of string copying
going on in there...


More information about the Python-list mailing list