Re: Counting all permutations of a substring

2006-04-06 Thread Chris Lasher
Great suggestions, guys! Thanks so much! And yes, I stand corrected. A better suited subject title would have been Counting all overlapping substrings. Thanks again, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Counting all permutations of a substring

2006-04-06 Thread Azolex
I wrote: [counting all (possibly overlapping) occurences of a substring in a string] def count_subs(s,subs,pos=0) : pos = 1+s.find(subs,pos) return pos and 1+count_subs(s,subs,pos) . now to push lisp-style to the extreme,

Re: Counting all permutations of a substring

2006-04-06 Thread Michele Simionato
Azolex wrote: Python 2.5a1 (r25a1:43589, Apr 5 2006, 10:36:43) [MSC v.1310 32 bit (Intel)] on win32 ... cnt_ss = lambda s,ss,p=-1,n=-1 : n if np else cnt_ss(s,ss,s.find(ss,p+1),n+1) sarcastic-mode Ah, the pleasure of having a ternary operator in the language! /sarcastic-mode

Counting all permutations of a substring

2006-04-05 Thread Chris Lasher
Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr = 'AA' I want to consider how many times one can count probestr ('AA') in targetstr ('AAA'). The value in this example is, obviously, 2: you can match

Re: Counting all permutations of a substring

2006-04-05 Thread [EMAIL PROTECTED]
Chris Lasher wrote: Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr = 'AA' I want to consider how many times one can count probestr ('AA') in targetstr ('AAA'). The value in this example is,

Re: Counting all permutations of a substring

2006-04-05 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: Chris Lasher wrote: Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr = 'AA' I want to consider how many times one can count probestr ('AA') in targetstr

Re: Counting all permutations of a substring

2006-04-05 Thread Andrew Gwozdziewycz
On Apr 5, 2006, at 5:07 PM, Chris Lasher wrote: Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr = 'AA' I want to consider how many times one can count probestr ('AA') in targetstr ('AAA').

Re: Counting all permutations of a substring

2006-04-05 Thread Azolex
[counting all (possibly overlapping) occurences of a substring in a string] def count_subs(s,subs,pos=0) : pos = 1+s.find(subs,pos) return pos and 1+count_subs(s,subs,pos) or equivalently def count_subs(s,subs) pos,cnt = 0,0 while True : pos = 1+s.find(subs,pos)