How to split string in equally long parts
Alexander Schmolck
a.schmolck at gmx.net
Tue Apr 8 19:42:33 EDT 2003
Carsten Gaebler <news at snakefarm.org> writes:
> Heiko Henkelmann wrote:
> > I need to split a string into an array of equally long substrings, like
> > e.g.:
> >
> > '1234567890' -> ['12', '34','56','78','90']
> >
> > What is the most efficient way to do this?
>
> I don't know how efficient it is but this is what came to my mind:
>
> import re
> filter(None, re.split('(.{2})', '1234567890'))
>
> cg.
>
why not just:
>>> import re
>>> re.findall('..', '123456')
['12', '34', '56']
alex
More information about the Python-list
mailing list