On Wed, Oct 1, 2008 at 6:00 PM, Danny Yoo <[EMAIL PROTECTED]> wrote:
>> Regular expressions are for processing strings, not loops.
>
> From a theoretical point of view, this isn't quite true: regular
> expressions can deal with sequences of things.

Sheesh! OK, *Python* regular expressions are for processing strings :-)

> If we want to be cute, we can also use the itertools.groupby()
> function to do the clumping of identical sequential values for us.
> For example:
>
> #################################################
>>>> for group in itertools.groupby('aaaabbbbcaaabaaaacc'):
> ...     print group[0], len(list(group[1]))

Hmm, I smell a one-liner here:
max(len(list(group[1])) for group in itertools.groupby('aaaabbbbcaaabaaaacc'))

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to