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

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


Andrew Koenig <ark at research.att.com> 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']

Aehm,

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

Greetings

Berthold
-- 
bhoel at web.de / http://starship.python.net/crew/bhoel/
        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