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
I think I can tell you WHY this happens, but I don't know a work-around
at the moment.
It seems as if only the following _a_ (A) are counted: a_A_a_A_
regards
Dirk
--
http://mail.python.org/mailman/listinfo/python-list
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
Dirk Hagemann [EMAIL PROTECTED] writes:
I think I can tell you WHY this happens, but I don't know a work-around
at the moment.
len(re.findall('_(?=a_)', '_a_a_a_a_'))
# untested
def countWithOverlaps(s, pat):
return len(re.findall(%s(?=%s) % (re.escape(pat[0]),
re.escape(pat[1:])),s))
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_
dont use 'str' as an identifier, it shadows the builtin str type.
howmuch = str.count(_a_)
print howmuch - 3
but the count return only 2
Ok
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
We were doing something like this last week
thestring = a_a_a_a_
for x in range(len(thestring)):
... try:
... thestring.count(_a_, x, x + 3)
... except ValueError:
... pass
--
http://mail.python.org/mailman/listinfo/python-list