Consecutive Character Sequences

George Sakkis gsakkis at rutgers.edu
Thu Jul 14 15:14:28 CEST 2005


"Aries Sun" <sun.aries at gmail.com> 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 it is again, just in case:

import itertools as it

def hasConsequent(aString, minConsequent):
    for _,group in it.groupby(aString):
        if len(list(group)) >= minConsequent:
            return True
    return False

Run it from a file instead of the command line and see if you get the same result.

I'm using 2.4:
>>> sys.version
'2.4 (#1, Mar 29 2005, 15:15:45) \n[GCC 3.3.3 (cygwin special)]'

I would be very surprised if something so crucial changed between 2.4.0 and 2.4.1. What does
[list(group) for _,group in it.groupby("taaypiqee88adbbba")]
return to you ?


George





More information about the Python-list mailing list