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

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-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: lst =

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

[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', '',

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 =

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', '', 'jyz', '',

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 = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf' o =

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 mainly

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 really