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