string.count issue (i'm stupid?)
Tim Chase
python.list at tim.thechases.com
Mon May 22 11:26:07 EDT 2006
I agree the docstring is a bit confusing and could be clarified
as to what's happening
> Can someone explain me this? And in which way i can count all
> the occurrence of a substring in a master string? (yes all
> occurrence reusing already counter character if needed)
You should be able to use something like
s = "a_a_a_a_"
count = len([i for i in range(len(s)) if s.startswith("_a_", i)])
which will count the way you wanted, rather than the currently
existing count() behavior.
-tkc
More information about the Python-list
mailing list