Consecutive Character Sequences

Aries Sun sun.aries at
Thu Jul 14 09:17:49 CEST 2005

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, minConsequent):
	for ch in aString:
		result = findall(ch*minConsequent, aString)
		if len(result) >= 1:
			return True
	return False

>>> hasConsequent(s, 2)
>>> hasConsequent(s, 3)
>>> hasConsequent(s, 4)

Aries Sun

More information about the Python-list mailing list