Splitting a string into groups of three characters

lemon97 at gmail.com lemon97 at gmail.com
Mon Aug 8 14:04:31 EDT 2005


Yes i know i made a mistake,
>['Hell','o W','orl','d']
but you know what I mean lol,

I'll probly use
John Machin's

 def nsplit(s, n):
    return [s[k:k+n] for k in xrange(0, len(s), n)]

It seems fast, and does not require any imports.

But anyways, thank you for all your help, you rock! :)




More information about the Python-list mailing list