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

Andrew Koenig ark at research.att.com
Thu Aug 15 23:04:19 CEST 2002


Berthold> 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']

Berthold> Aehm,

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

Oops -- I cut and pasted from the wrong window.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list