[Tutor] Splitting long string into same len parts

Victor Bouffier victor at grupocdm.com
Thu Feb 9 08:43:22 CET 2006


Hi Emile and John,

Thanks a lot for your insight. There is always a better way, or at least
a more pythonic one.

Take care.
Victor.

On Wed, 2006-02-08 at 22:36 -0800, Emile van Sebille wrote:
> "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
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list