Re: Consecutive Character Sequences

2005-07-14 Thread Aries Sun
Hi George, Here's the result: >>> [list(group) for _,group in it.groupby("taaypiqee88adbbba")] [['t'], ['a', 'a'], ['y'], ['p'], ['i'], ['q'], ['e', 'e'], ['8', '8'], ['a'], ['d'], ['b', 'b', 'b'], ['a']] >>> [len(list(group)) for _,group in it.groupby("taaypiqee88adbbba")] [1, 2, 1, 1, 1, 1, 2, 2

Re: Consecutive Character Sequences

2005-07-14 Thread Walter Brunswick
Thank you [EMAIL PROTECTED] <[EMAIL PROTECTED]>, George Sakkis <[EMAIL PROTECTED]> and Aries Sun <[EMAIL PROTECTED]> for your code contributions. I haven't tested them yet, but they look alright and enough for me to work with. Thanks to everyone else for your comments. W. Brunswick. -- http

Re: Consecutive Character Sequences

2005-07-14 Thread Sion Arrowsmith
Aries Sun <[EMAIL PROTECTED]> wrote: >I used Python 2.4.1, the following are the command lines. >But the reslut was still False. Is there anything wrong with below >codes? import itertools as it def hasConsequent(aString, minConsequent): > for _,group in it.groupby(aString): >

Re: Consecutive Character Sequences

2005-07-14 Thread George Sakkis
"Aries Sun" <[EMAIL PROTECTED]> wrote: > Hi George, > I used Python 2.4.1, the following are the command lines. > But the reslut was still False. Is there anything wrong with below > codes?hasConsequent("taaypiqee88adbbba", 3) All indentation was lost in your message, so I'm not quite sure; here

Re: Consecutive Character Sequences

2005-07-14 Thread Aries Sun
Hi George, I used Python 2.4.1, the following are the command lines. But the reslut was still False. Is there anything wrong with below codes? >>> import itertools as it >>> def hasConsequent(aString, minConsequent): for _,group in it.groupby(aString): if len(list(group)) >

Re: Consecutive Character Sequences

2005-07-14 Thread George Sakkis
"Aries Sun" <[EMAIL PROTECTED]> wrote: > I have tested George's solutions, it seems not complete. When pass (s, > 3) to the function hasConsequent(), it returns the wrong result. What are you talking about ? I get the correct answer for >>> hasConsequent("taaypiqee88adbbba", 3) True George --

Re: Consecutive Character Sequences

2005-07-14 Thread Aries Sun
I have tested George's solutions, it seems not complete. When pass (s, 3) to the function hasConsequent(), it returns the wrong result. The following is my approach. The performence may be not so good. There must be better ones. >>> from re import findall >>> def hasConsequent(aString, minConsequ

Re: Consecutive Character Sequences

2005-07-13 Thread George Sakkis
"Walter Brunswick" <[EMAIL PROTECTED]> wrote: > Is there any way to [efficiently] iterate through a sequence of characters to > find N [or more] consecutive equivalent characters? > > So, for example, the string "taaypiqee88adbbba" would return 1 if the number > (of consequtive characters) suppl

Re: Consecutive Character Sequences

2005-07-13 Thread [EMAIL PROTECTED]
Walter Brunswick wrote: > Is there any way to [efficiently] iterate through a sequence of characters to > find N [or more] consecutive equivalent characters? > > So, for example, the string "taaypiqee88adbbba" would return 1 if the number > (of consequtive characters) supplied in the parameters

Re: Consecutive Character Sequences

2005-07-13 Thread Peter Hansen
Walter Brunswick wrote: > Is there any way to [efficiently] iterate through a sequence of characters to > find N [or more] consecutive equivalent characters? > > So, for example, the string "taaypiqee88adbbba" would return 1 if the number > (of consequtive characters) supplied in the parameters