Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Alan Gauld
"Jerry Hill" <[EMAIL PROTECTED]> wrote You can do it with slice assignment too: a = [1, 2, 3, 4] a[1:3] = [[7, 8]] a [1, [7, 8], 4] Now, which way is better? The answer depends on context. If, conceptually, you are removing two elements from a list, then adding a new element which is itse

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Douglas Drumond
Thanks, Ryan, for detailed explanation; I'm learning Python now, too, so I don't know exactly how stuff works. []'s Douglas On Mon, Jun 30, 2008 at 18:33, Lie Ryan <[EMAIL PROTECTED]> wrote: >> You can do it with slice assignment too: >> >>> a = [1, 2, 3, 4] >> >>> a[1:3] = [[7, 8]] >> >>> a

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Lie Ryan
> You can do it with slice assignment too: > >>> a = [1, 2, 3, 4] > >>> a[1:3] = [[7, 8]] > >>> a > [1, [7, 8], 4] >  > Now, which way is better? The answer depends on context. The best > way to write it is in the manner that it makes the most sense to > someone reading your program (including

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Jerry Hill
On Mon, Jun 30, 2008 at 4:47 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > Show me a better way? You can do it with slice assignment too: >>> a = [1, 2, 3, 4] >>> a[1:3] = [[7, 8]] >>> a [1, [7, 8], 4] Now, which way is better? The answer depends on context. The best way to write it is in the ma

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Dick Moores
At 01:39 PM 6/30/2008, Dick Moores wrote: At 11:01 PM 6/29/2008, wesley chun wrote: > > e.g. can you predict the result of the following operations without trying it? > > > > a = [1, 2, 3, 4] > > a[1:3] = [7, 8] > > print a > >  [1, 7, 8, 4]   Whew! >  (I really wasn't positive that it shouldn't

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Dick Moores
At 11:01 PM 6/29/2008, wesley chun wrote: > > e.g. can you predict the result of the following operations without trying it? > > > > a = [1, 2, 3, 4] > > a[1:3] = [7, 8] > > print a > >  [1, 7, 8, 4]   Whew! >  (I really wasn't positive that it shouldn't be [1, [7, 8], 4] !) good job dick! of cou

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-29 Thread wesley chun
> > e.g. can you predict the result of the following operations without trying > > it? > > > > a = [1, 2, 3, 4] > > a[1:3] = [7, 8] > > print a > > [1, 7, 8, 4] Whew! > (I really wasn't positive that it shouldn't be [1, [7, 8], 4] !) good job dick! of course, you *know* i'm going to ask this.

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-29 Thread Dick Moores
At 03:39 PM 6/29/2008, John Fouhy wrote: On 28/06/2008, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm very familiar with appending x to a list, s, using s.append(x), however, > I've never understood what the docs mean by > > s.append(x) same as s[len(s):len(s)] = [x] In addition to Douglas's c

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-29 Thread Dick Moores
At 03:39 PM 6/29/2008, John Fouhy wrote: On 28/06/2008, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm very familiar with appending x to a list, s, using s.append(x), however, > I've never understood what the docs mean by > > s.append(x) same as s[len(s):len(s)] = [x] In addition to Douglas's c

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-29 Thread John Fouhy
On 28/06/2008, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm very familiar with appending x to a list, s, using s.append(x), however, > I've never understood what the docs mean by > > s.append(x) same as s[len(s):len(s)] = [x] In addition to Douglas's comment, do you understand how assignment with

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-27 Thread Dick Moores
At 06:27 PM 6/27/2008, Douglas Drumond wrote: >>> s = [1,2,3] >>> x = 5 >>> s[len(s):len(s)] = [x]   # (1)   >>> s  [1, 2, 3, 5] When you did s[len(s):len(s)] you got the slice begining at len(s) with end at len(s) - 1, ie, nothing. At step (1), len(s) = 3, so you did s[3:3] = [x

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-27 Thread Douglas Drumond
> > >>> s = [1,2,3] > >>> x = 5 > >>> s[len(s):len(s)] = [x] # (1) > >>> s [1, 2, 3, 5] When you did s[len(s):len(s)] you got the slice begining at len(s) with end at len(s) - 1, ie, nothing. At step (1), len(s) = 3, so you did s[3:3] = [x]. It meant that the slice starting at index

[Tutor] s[len(s):len(s)] = [x] ??

2008-06-27 Thread Dick Moores
I'm very familiar with appending x to a list, s, using s.append(x), however, I've never understood what the docs mean by s.append(x) same as s[len(s):len(s)] = [x] (See ) Trying it, >>> s = [1,2,3] >>> x = 5 >>> s[len(s):len(s)] = [x] >>> s[len