Re: explain slice assignment to newb

2008-09-20 Thread Stephen Horne
On Sat, 20 Sep 2008 14:20:20 -0700 (PDT), Andrew <[EMAIL PROTECTED]> wrote: >please explain this behavior to a newb: > a = [1,2,3,4] b = ["a","b","c","d"] a[0:2] = b[0:2] The slice [0:2] represent positions 0 <= x < 2 Replaces the [1, 2] from [1, 2, 3, 4] with ['a', 'b'] Result: a

Re: explain slice assignment to newb

2008-09-20 Thread Terry Reedy
Andrew wrote: please explain this behavior to a newb: Read the section on sequence slicing in the Library Reference. Use the interactive interpreter or IDLE to perform experiments, like you did, until you understand to your satisfaction. -- http://mail.python.org/mailman/listinfo/python-li

Re: explain slice assignment to newb

2008-09-20 Thread Sean DiZazzo
On Sep 20, 2:20 pm, Andrew <[EMAIL PROTECTED]> wrote: > please explain this behavior to a newb: > > >>> a = [1,2,3,4] > >>> b = ["a","b","c","d"] > >>> a > [1, 2, 3, 4] > >>> b > > ['a', 'b', 'c', 'd'] > > >>> a[0:2] > [1, 2] > >>> a > [1, 2, 3, 4] > >>> b[2:4] > ['c', 'd'] > >>> a[0:2] = b[0:2] >

explain slice assignment to newb

2008-09-20 Thread Andrew
please explain this behavior to a newb: >>> a = [1,2,3,4] >>> b = ["a","b","c","d"] >>> a [1, 2, 3, 4] >>> b ['a', 'b', 'c', 'd'] >>> a[0:2] [1, 2] >>> a [1, 2, 3, 4] >>> b[2:4] ['c', 'd'] >>> a[0:2] = b[0:2] >>> b[2:4] = a[2:4] >>> a ['a', 'b', 3, 4] >>> b ['a', 'b', 3, 4] >>> -- http://mail.pyt