[Tutor] Splitting long string into same len parts
Emile van Sebille
emile at fenx.com
Thu Feb 9 07:36:33 CET 2006
"Andre Roberge" <andre.roberge at gmail.com> wrote in message
> There's a tongue-in-cheek quote that I really like:
> "Sometimes you have a programming problem and it seems like the best
> solution is to use regular expressions; now you have two problems."
+1 -- There are some things re is good for, but mainly it's good
motivation to just do it in python...
> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf'
> length = len(n)
> o = []
> for i in range(0, length, 3):
> o.append(n[i:i+3])
>
Or as a one-liner...
o = [ n[ii:ii+3] for ii in range(0,len(n),3) ]
Emile
More information about the Tutor
mailing list