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
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.
...
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 =
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
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', '',
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 =
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', '',
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 =
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
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
10 matches
Mail list logo