slicing lists

Ivan Illarionov ivan.illarionov at gmail.com
Wed May 7 21:19:02 EDT 2008


On Thu, 08 May 2008 01:15:43 +0000, 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
>>  <ivan.illarionov at gmail.com> wrote:
>>  > On Wed, 07 May 2008 23:29:27 +0000, 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 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)
> 
> So it should be x[0] + x[2:6] or x[0].extend(x[2:6])

Oh, I meant
[x[0]] + x[2:6]
or
y = [x[0]]
y.extend(x[2:6])

Sorry






More information about the Python-list mailing list