On Sep 2, 3:55 pm, bvdp b...@mellowood.ca wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form 1:2, 1,
:-1, etc. and feed it to slice() and then apply the result to an
On Sep 2, 8:52 pm, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
On Wed, 02 Sep 2009 17:32:09 -0700, Bob van der Poel wrote:
Actually, nither this or Jan's latest is working properly. I don't know
if it's the slice() function or what (I'm using python 2.5). But:
x =
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form 1:2, 1,
:-1, etc. and feed it to slice() and then apply the result to an
existing list?
For example, I have a normal python list.
bvdp wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form 1:2, 1,
:-1, etc. and feed it to slice() and then apply the result to an
existing list?
For example, I have a normal
On 2009-09-02 16:55 PM, bvdp wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form 1:2, 1,
:-1, etc. and feed it to slice() and then apply the result to an
existing list?
For
03-09-2009 o 00:11:17 MRAB pyt...@mrabarnett.plus.com wrote:
bvdp wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form 1:2, 1,
:-1, etc. and feed it to slice() and then apply
Erratum:
eval(str(x) + s)
-- but it's worse: less secure (e.g. if s could be user-typed) and most
probably much more time-consuming (especially the latter).
There should be *repr* instead of *str*.
*j
--
Jan Kaliszewski (zuo) z...@chopin.edu.pl
--
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But, if I have
s = [:2] then I get:
x[slice(*[int(i) for i in s.strip([]).split(:)])]
Traceback (most recent call last):
File stdin, line 1, in module
ValueError:
Of course, you could also do something like this:
eval('x' + s)
or
eval(str(x) + s)
Yes, I have user inputed 's'. So, if I can't get the generalized list
version from Robert working I'll have to use this. Speed is not a big
deal in this. As to malicious input, I could pretty
On Wed, 02 Sep 2009 23:57:48 +0100, Bob van der Poel b...@mellowood.ca
wrote:
Of course, you could also do something like this:
eval('x' + s)
or
eval(str(x) + s)
Yes, I have user inputed 's'. So, if I can't get the generalized list
version from Robert working I'll have to use
On 2009-09-02 17:55 PM, Bob van der Poel wrote:
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But, if I have
s = [:2] then I get:
x[slice(*[int(i) for i in s.strip([]).split(:)])]
Traceback (most recent call
On Wed, 02 Sep 2009 16:41:34 -0700, Bob van der Poel wrote:
But, translating 1, 2 or 3 ints into a valid splice isn't quit that
easy? I could figure each value, and convert them to either int or None
(key is the None! From my previous try '' doesn't work!)
But, I still need three possible
Bob van der Poel wrote:
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But, if I have
s = [:2] then I get:
x[slice(*[int(i) for i in s.strip([]).split(:)])]
Traceback (most recent call last):
File stdin, line 1,
On Sep 2, 4:16 pm, Rhodri James rho...@wildebst.demon.co.uk wrote:
On Wed, 02 Sep 2009 23:57:48 +0100, Bob van der Poel b...@mellowood.ca
wrote:
Of course, you could also do something like this:
eval('x' + s)
or
eval(str(x) + s)
Yes, I have user inputed 's'. So, if I
On Sep 2, 4:43 pm, Jan Kaliszewski z...@chopin.edu.pl wrote:
03-09-2009 o 00:55:10 Bob van der Poel b...@mellowood.ca wrote:
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But, if I have
s = [:2] then I get:
On Sep 2, 5:16 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
On Wed, 02 Sep 2009 16:41:34 -0700, Bob van der Poel wrote:
But, translating 1, 2 or 3 ints into a valid splice isn't quit that
easy? I could figure each value, and convert them to either int or None
(key is
03-09-2009 o 00:55:10 Bob van der Poel b...@mellowood.ca wrote:
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But, if I have
s = [:2] then I get:
x[slice(*[int(i) for i in s.strip([]).split(:)])]
Traceback (most
On Sep 2, 4:27 pm, Ethan Furman et...@stoneleaf.us wrote:
Bob van der Poel wrote:
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But, if I have
s = [:2] then I get:
x[slice(*[int(i) for i in
On Wed, 02 Sep 2009 17:36:36 -0700, Bob van der Poel b...@mellowood.ca
wrote:
On Sep 2, 4:27 pm, Ethan Furman et...@stoneleaf.us wrote:
Bob van der Poel wrote:
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
Thanks.
Almost works :)
For s=[2] and s=[1:2] it's fine. But,
On Wed, 02 Sep 2009 17:32:09 -0700, Bob van der Poel wrote:
Actually, nither this or Jan's latest is working properly. I don't know
if it's the slice() function or what (I'm using python 2.5). But:
x = [1,2,3,4,5]
slice_string=2
items = [int(n) if n else None for n in
On Sep 2, 4:55 pm, bvdp b...@mellowood.ca wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Well, this is a nice puzzler, better than a sudoku. Maybe a quick
parser with pyparsing will give you some guidance on how to do this
21 matches
Mail list logo