how to split a string (or sequence) into pairs of characters?

Berthold Höllmann bhoel at
Thu Aug 15 22:31:27 CEST 2002

Andrew Koenig <ark at> writes:

> Jason> Can anyone come up with a better way of performing these
> Jason> operations? Extra kudos if it easily extends to any sublength
> Jason> and not just pairs.
>         >>> import re
>         >>> re.findall('..', 'aabbccddee')
>         ['ab', 'cd', 'ef']


>>> re.findall('..', 'aabbccddee')
['aa', 'bb', 'cc', 'dd', 'ee']


bhoel at /
        It is unlawful to use this email address for unsolicited ads
        (USC Title 47 Sec.227). I will assess a US$500 charge for
        reviewing and deleting each unsolicited ad.

More information about the Python-list mailing list