Processing text using python

Alex Martelli aleaxit at yahoo.com
Mon Feb 20 17:43:05 EST 2006


Xavier Morel <xavier.morel at masklinn.net> wrote:

> Fredrik Lundh wrote:
> > did you read the string chapter in the tutorial ?
> > 
> > http://docs.python.org/tut/node5.html#SECTION005120000000000000000
> > 
> > around the middle of that chapter, there's a section on slicing:
> > 
> >     "substrings can be specified with the slice notation: two indices
> >     separated by a colon"
> > 
> Fredrik, how would you use slices to split a string by groups of 3 
> characters?

I can't answer for him, but maybe:

  [s[i:i+3] for i in xrange(0, len(s), 3)]

...?


Alex



More information about the Python-list mailing list