On Sep 2, 8:52 pm, Steven D'Aprano
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 = [1,2,3,4,5]
> > slice_string="2"
> >
On Sep 2, 3: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 lis
On Sep 2, 4: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!
>
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
without a parser
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 slice_string.s
On Wed, 02 Sep 2009 17:36:36 -0700, Bob van der Poel
wrote:
On Sep 2, 4:27 pm, Ethan Furman 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]" t
On Sep 2, 4:27 pm, Ethan Furman 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 Sep 2, 5:16 pm, Steven D'Aprano 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 the None! From my previous try '
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 "", lin
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 possib
On Sep 2, 4:43 pm, "Jan Kaliszewski" wrote:
> 03-09-2009 o 00:55:10 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:
>
>
On Sep 2, 4:16 pm, "Rhodri James" wrote:
> On Wed, 02 Sep 2009 23:57:48 +0100, Bob van der Poel
> 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 generaliz
03-09-2009 o 00:55:10 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 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 c
On Wed, 02 Sep 2009 23:57:48 +0100, Bob van der Poel
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 this. Speed is not
> 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
> 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 "", line 1, in
ValueError:
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)
--
http://mail.python.org/mailman/listinfo/python-list
03-09-2009 o 00:11:17 MRAB 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 the result to an
exis
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?
F
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 nor
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 lis
21 matches
Mail list logo