counting number of (overlapping) occurances

Paul Rubin http
Fri Mar 10 00:36:19 EST 2006


"John" <weekender_ny at yahoo.com> writes:
> if S1 = "AAAA"
> and S2 = "AA"
> 
> then the count is 3. Is there an easy way to do this in python?
> I was trying to use the "count" function but it does not do
> overlapping counts it seems.

len([1 for i in xrange(len(s1)) if s1[i:].startswith(s2)])



More information about the Python-list mailing list