Re: [Tutor] Splitting long string into same len parts

2006-02-10 Thread Victor Bouffier
On Thu, 2006-02-09 at 09:45 +, Alan Gauld wrote: > > Define easier :-) > Right! > You could just use string slicing and a stepsize of 3 in range: > > lst = [mystring[index : index+3] for index in range(0,len(mystring),3)] > Ever since I found them, list comprehensions are my favorites.

Re: [Tutor] Splitting long string into same len parts

2006-02-10 Thread Victor Bouffier
Aha!!! I believe this is what I was looking for in the first place (not that I will use it anyway, given the alternatives provided by others). I guess that coming from a Perl background, which as you know includes regexes as part of the core language, you tend to look to all solutions through this

Re: [Tutor] Splitting long string into same len parts

2006-02-10 Thread Victor Bouffier
WOW!! This is really great. Thanks Ken. This first one is definitely going to my personal scripts directory ;-) Victor On Thu, 2006-02-09 at 05:56 -0500, Kent Johnson wrote: > Victor Bouffier wrote: > > Hi to all, > > > > I'd like to split a long string into equally long strings (len(str) = >

Re: [Tutor] Splitting long string into same len parts

2006-02-09 Thread Kent Johnson
Victor Bouffier wrote: > Hi to all, > > I'd like to split a long string into equally long strings (len(str) = > 3). This is a very popular topic in the Python Cookbook. See for example http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425044 http://aspn.activestate.com/ASPN/Cookbook/Python

Re: [Tutor] Splitting long string into same len parts

2006-02-09 Thread Alan Gauld
Hi Victor, > I'd like to split a long string into equally long strings (len(str) = > 3). I did the following using regexes: > This is what I needed. Is there an easier or more straightforward way to > do this? Define easier :-) You could just use string slicing and a stepsize of 3 in range: ls

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Victor Bouffier
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" <[EMAIL PROTECTED]> wrote in message > > > There's a tongue-in-cheek quote that I rea

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Emile van Sebille
"Andre Roberge" <[EMAIL PROTECTED]> 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

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Andre Roberge
On 2/8/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 8 Feb 2006, Victor Bouffier wrote: > > > Hi to all, > > > > I'd like to split a long string into equally long strings (len(str) = > > 3). I did the following using regexes: > > > > >>> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zj

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Danny Yoo
On Wed, 8 Feb 2006, Victor Bouffier wrote: > Hi to all, > > I'd like to split a long string into equally long strings (len(str) = > 3). I did the following using regexes: > > >>> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf' > >>> o = re.split(r'(...)', n) > >>> print o > ['', 'xb1', ''

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread John Fouhy
On 09/02/06, Victor Bouffier <[EMAIL PROTECTED]> wrote: > I'd like to split a long string into equally long strings (len(str) = > 3). I did the following using regexes: Remember that a string is just like a list (except that you can't modify it). So, for instance: >>> n = 'xb1jyzqnd1eenkokqnhep6

[Tutor] Splitting long string into same len parts

2006-02-08 Thread Victor Bouffier
Hi to all, I'd like to split a long string into equally long strings (len(str) = 3). I did the following using regexes: >>> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf' >>> o = re.split(r'(...)', n) >>> print o ['', 'xb1', '', 'jyz', '', 'qnd', '', '1ee', '', 'nko', '', 'kqn', '', 'hep'