Re: slicing lists

2008-05-10 Thread castironpi
On May 9, 3:17 pm, [EMAIL PROTECTED] wrote: > On May 9, 10:11 am, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > > > > > > > [EMAIL PROTECTED] wrote: > > > The only thing is, is there is another natural meaning to [a,b:c]. > > > > Counting grids on the diagonals, the rational set is well defined: > > >

Re: slicing lists

2008-05-09 Thread castironpi
On May 9, 10:11 am, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > The only thing is, is there is another natural meaning to [a,b:c]. > > > Counting grids on the diagonals, the rational set is well defined: > > > 0: 0, 0 > > 1: 1, 0 > > 2: 0, 1 > > 3: 2, 0 > > 4: 1, 1 > > 5

Re: slicing lists

2008-05-09 Thread Yves Dorfsman
[EMAIL PROTECTED] wrote: The only thing is, is there is another natural meaning to [a,b:c]. Counting grids on the diagonals, the rational set is well defined: 0: 0, 0 1: 1, 0 2: 0, 1 3: 2, 0 4: 1, 1 5: 0, 2 6: 3, 0 7: 2, 1 ... Thencefore ( 2, 0 ) : ( 3, 0 ) is well defined. Thencefore, a,b:

Re: slicing lists

2008-05-09 Thread castironpi
On May 9, 1:23 am, "Ian Kelly" <[EMAIL PROTECTED]> wrote: > On Wed, May 7, 2008 at 5:29 PM, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > > Is there a way to do: > > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > x[0,2:6] > > > That would return: > > [0, 3, 4, 5, 6] > > > I am surprised this notation is not

Re: slicing lists

2008-05-08 Thread Ian Kelly
On Wed, May 7, 2008 at 5:29 PM, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > Is there a way to do: > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > x[0,2:6] > > That would return: > [0, 3, 4, 5, 6] > > I am surprised this notation is not supported, it seems intuitive. > A concrete example of the sort of thing

Re: slicing lists

2008-05-08 Thread Yves Dorfsman
MRAB wrote: You should've read the thread entitled "Why don't generators execute until first yield?"! :-) Michael Torrie gave the URL http://www.dabeaz.com/generators/Generators.pdf. Your example can be rewritten as follows: p = file('/etc/passwd') # No need for readlines() because file's itera

Re: slicing lists

2008-05-08 Thread MRAB
On May 8, 4:34 am, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > Miles wrote: > > On Wed, May 7, 2008 at 7:46 PM, Ivan Illarionov > > > > Is there a way to do: > > > > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > > x[0,2:6] > > > > > That would return: > > > > [0, 3, 4, 5, 6] > > Arg... Yes, th

Re: slicing lists

2008-05-08 Thread Boris Borcic
Yves Dorfsman wrote: So would it be a worthy addition to python, to add it right in the core of the language, and hopefully in an efficient manner ? Note that the s[0,2:6] syntax is currently allowed because of the distinct semantics that the Numeric module and its successors numarray and

Re: slicing lists

2008-05-07 Thread George Sakkis
On May 7, 11:34 pm, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > So would it be a worthy addition to python, to add it right in the core of > the language, and hopefully in an efficient manner ? Given that it's a straightforward generalization of the existing slicing syntax, it sure does make sense

Re: slicing lists

2008-05-07 Thread Yves Dorfsman
Miles wrote: On Wed, May 7, 2008 at 7:46 PM, Ivan Illarionov > > Is there a way to do: > > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > x[0,2:6] > > > > That would return: > > [0, 3, 4, 5, 6] Arg... Yes, this is a typo, I meant: [1, 3, 4, 5, 6] I think Yves meant to return [1, 3, 4, 5

Re: slicing lists

2008-05-07 Thread [EMAIL PROTECTED]
On May 7, 6:13 pm, Miles <[EMAIL PROTECTED]> wrote: (snipped) > I think Yves meant to return [1, 3, 4, 5, 6], as in Perl's list slicing: > > my @x = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); > return @x[0, 2..6]; // returns (1, 3, 4, 5, 6) > > This isn't incredibly efficient, but it does what you want

Re: slicing lists

2008-05-07 Thread Ivan Illarionov
On Thu, 08 May 2008 01:15:43 +, Ivan Illarionov wrote: > On Wed, 07 May 2008 21:13:27 -0400, Miles wrote: > >> On Wed, May 7, 2008 at 7:46 PM, Ivan Illarionov >> <[EMAIL PROTECTED]> wrote: >> > On Wed, 07 May 2008 23:29:27 +, Yves Dorfsman wrote: >> > >> > > Is there a way to do: >>

Re: slicing lists

2008-05-07 Thread Ivan Illarionov
On Wed, 07 May 2008 21:13:27 -0400, Miles wrote: > On Wed, May 7, 2008 at 7:46 PM, Ivan Illarionov > <[EMAIL PROTECTED]> wrote: > > On Wed, 07 May 2008 23:29:27 +, Yves Dorfsman wrote: > > > > > Is there a way to do: > > > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > x[0,2:6] > > > >

Re: slicing lists

2008-05-07 Thread Miles
On Wed, May 7, 2008 at 7:46 PM, Ivan Illarionov <[EMAIL PROTECTED]> wrote: > On Wed, 07 May 2008 23:29:27 +, Yves Dorfsman wrote: > > > Is there a way to do: > > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > x[0,2:6] > > > > That would return: > > [0, 3, 4, 5, 6] > > IMHO this notat

Re: slicing lists

2008-05-07 Thread castironpi
On May 7, 6:58 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote: > On Wed, 07 May 2008 23:46:33 +, Ivan Illarionov wrote: > > On Wed, 07 May 2008 23:29:27 +, Yves Dorfsman wrote: > > >> Is there a way to do: > >> x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > >> x[0,2:6] > > >> That would return: > >>

Re: slicing lists

2008-05-07 Thread Ivan Illarionov
On Wed, 07 May 2008 23:46:33 +, Ivan Illarionov wrote: > On Wed, 07 May 2008 23:29:27 +, Yves Dorfsman wrote: > >> Is there a way to do: >> x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> x[0,2:6] >> >> That would return: >> [0, 3, 4, 5, 6] > > IMHO this notation is confusing. > > What's wrong

Re: slicing lists

2008-05-07 Thread Ivan Illarionov
On Wed, 07 May 2008 23:29:27 +, Yves Dorfsman wrote: > Is there a way to do: > x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > x[0,2:6] > > That would return: > [0, 3, 4, 5, 6] IMHO this notation is confusing. What's wrong with: [0]+x[2:6] > I am surprised this notation is not supported, it seems