Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Debajit Adhikary
On Oct 18, 9:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > Debajit Adhikary <[EMAIL PROTECTED]> wrote: > > > How does "a.extend(b)" compare with "a += b" when it comes to > > performance? Does a + b create a completely new list that it assigns > > back to a? If so, a.extend(b) would seem to be

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread J. Clifford Dyer
On Thu, Oct 18, 2007 at 11:57:10AM -, Paul Hankin wrote regarding Re: Appending a list's elements to another list using a list comprehension: > > Not to me: I can never remember which of a.append and a.extend is > which. Falling back to a = a + b is exactly what you want.

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Alex Martelli
Debajit Adhikary <[EMAIL PROTECTED]> wrote: ... > How does "a.extend(b)" compare with "a += b" when it comes to > performance? Does a + b create a completely new list that it assigns > back to a? If so, a.extend(b) would seem to be faster. How could I > verify things like these? That's what the

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Hrvoje Niksic
Paul Hankin <[EMAIL PROTECTED]> writes: > Not to me: I can never remember which of a.append and a.extend is > which. Interesting, with me it's the other way around. Maybe it's because I used Python before extend was available. > Falling back to a = a + b is exactly what you want. Not if you wa

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Bruno Desthuilliers
Debajit Adhikary a écrit : > I have two lists: > > a = [1, 2, 3] > b = [4, 5, 6] > > What I'd like to do is append all of the elements of b at the end of > a, so that a looks like: > > a = [1, 2, 3, 4, 5, 6] > > I can do this using > > map(a.append, b) And what about a.extend(b) ? > How do I

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Paul Hankin
On Oct 18, 10:21 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Paul Hankin <[EMAIL PROTECTED]> writes: > > On Oct 17, 10:03 pm, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > >> How does "a.extend(b)" compare with "a += b" when it comes to > >> performance? Does a + b create a completely new list t

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Hrvoje Niksic
Paul Hankin <[EMAIL PROTECTED]> writes: > On Oct 17, 10:03 pm, Debajit Adhikary <[EMAIL PROTECTED]> wrote: >> How does "a.extend(b)" compare with "a += b" when it comes to >> performance? Does a + b create a completely new list that it assigns >> back to a? If so, a.extend(b) would seem to be fast

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Gabriel Genellina
En Wed, 17 Oct 2007 18:03:56 -0300, Debajit Adhikary <[EMAIL PROTECTED]> escribió: > What in general is a good way to learn about little things like these? > (I'm fairly new to the language) > > A google search for 'python list methods" did not turn up the + > operator anywhere for me. Where cou

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2007 21:40:40 +, Paul Hankin wrote: > On Oct 17, 10:03 pm, Debajit Adhikary <[EMAIL PROTECTED]> wrote: >> How does "a.extend(b)" compare with "a += b" when it comes to >> performance? Does a + b create a completely new list that it assigns >> back to a? If so, a.extend(b) would

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2007 23:46:25 +, Debajit Adhikary wrote: > On Oct 17, 5:40 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: >> To answer your question though: a += b is *not* the same as a = a + b. >> The latter would create a new list and assign it to a, whereas a += b >> updates a in-place. > > I

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Robert Kern
Debajit Adhikary wrote: > On Oct 17, 5:40 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: >> To answer your question though: a += b is *not* the same as a = a + b. >> The latter would create a new list and assign it to a, whereas a += b >> updates a in-place. > > I know I'm being a little finicky here,

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Debajit Adhikary
On Oct 17, 5:40 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > To answer your question though: a += b is *not* the same as a = a + b. > The latter would create a new list and assign it to a, whereas a += b > updates a in-place. I know I'm being a little finicky here, but how would someone know that

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Paul Hankin
On Oct 17, 10:03 pm, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > How does "a.extend(b)" compare with "a += b" when it comes to > performance? Does a + b create a completely new list that it assigns > back to a? If so, a.extend(b) would seem to be faster. How could I > verify things like these? U

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Debajit Adhikary
On Oct 17, 4:41 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Wed, 2007-10-17 at 20:27 +, Debajit Adhikary wrote: > > I have two lists: > > > a = [1, 2, 3] > > b = [4, 5, 6] > > > What I'd like to do is append all of the elements of b at the end of > > a, so that a looks like: > > > a = [1,

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Paul Hankin
On Oct 17, 9:27 pm, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > I have two lists: > > a = [1, 2, 3] > b = [4, 5, 6] > > What I'd like to do is append all of the elements of b at the end of > a, so that a looks like: > > a = [1, 2, 3, 4, 5, 6] > > I can do this using > > map(a.append, b) > > How d

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Carsten Haese
On Wed, 2007-10-17 at 20:27 +, Debajit Adhikary wrote: > I have two lists: > > a = [1, 2, 3] > b = [4, 5, 6] > > What I'd like to do is append all of the elements of b at the end of > a, so that a looks like: > > a = [1, 2, 3, 4, 5, 6] > > I can do this using > > map(a.append, b) > > How

Re: Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Oct 2007 20:27:14 +, Debajit Adhikary wrote: > I have two lists: > > a = [1, 2, 3] > b = [4, 5, 6] > > What I'd like to do is append all of the elements of b at the end of > a, so that a looks like: > > a = [1, 2, 3, 4, 5, 6] > > I can do this using > > map(a.append, b) This i

Appending a list's elements to another list using a list comprehension

2007-10-17 Thread Debajit Adhikary
I have two lists: a = [1, 2, 3] b = [4, 5, 6] What I'd like to do is append all of the elements of b at the end of a, so that a looks like: a = [1, 2, 3, 4, 5, 6] I can do this using map(a.append, b) How do I do this using a list comprehension? (In general, is using a list comprehension pref