string.count issue (i'm stupid?)

Diez B. Roggisch deets at nospam.web.de
Mon May 22 07:13:16 EDT 2006


Matteo Rattotti wrote:

> Hi all,
> 
> i've noticed a strange beaviour of string.count:
> 
> in my mind this code must work in this way:
> 
> str = "a_a_a_a_"
> howmuch = str.count("_a_")
> print howmuch -> 3
> 
> but the count return only 2
> 
> Ok this can be fine, but why? The doc string tell that count will
> return the number of substring in the master string, if we spoke about
> substring i count 3 substring...

It appears to be a documentation bug. It should say something about
non-overlapping occurences.

Better would be of course to introduce a parameter that defines the
behavior, either overlapping or not.

Diez




More information about the Python-list mailing list