Re: Passing a list into a list .append() method

2014-09-09 Thread Rustom Mody
On Tuesday, September 9, 2014 11:25:29 AM UTC+5:30, JBB wrote: > I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'bink

Re: Passing a list into a list .append() method

2014-09-09 Thread JBB
Peter Otten <__peter__ web.de> writes: [Deletia] To Peter Otten and Paul Kroeger: Thank you both, very much. I think I now get why the binding works as it does in addition to why the list() approach worked. (Third attempt - priors not going through, please excuse any repetition) JBB -- h

Re: Passing a list into a list .append() method

2014-09-09 Thread JBB
Paul Kroeger prz-wugen.com> writes: > > Hello, > > I'm myself still learning Python, so others may please correct me, if > I'm wrong. ... > I hope, the above helps to understand why this behaviour.is to be > expected. > To Peter Otten and Paul Kroeger: Thank you both, very much. I think I no

Re: Passing a list into a list .append() method

2014-09-09 Thread Paul Kroeger
Hello, I'm myself still learning Python, so others may please correct me, if I'm wrong. Consider the following sentence of your link "jeffknupp.com/...": "some_guy and first_names[0] both refer to the same object" This is what is going on here. Am Dienstag, den 09.09.2014, 05:50 + schrieb

Re: Passing a list into a list .append() method

2014-09-09 Thread Peter Otten
JBB wrote: > I have a list with a fixed number of elements which I need to grow; ie. > add rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'binky', ''], ... ] > > This is a reduced representatio

Re: Passing a list into a list .append() method

2014-09-09 Thread JBB
Frank Millman chagford.com> writes: > > > "JBB" gmail.com> wrote in message > news:loom.20140909T073428-713 post.gmane.org... > >I have a list with a fixed number of elements which I need to grow; ie. add > > rows of a fixed number of elements, some of which will be blank. ... > I am sure th

Re: Passing a list into a list .append() method

2014-09-08 Thread Frank Millman
"JBB" wrote in message news:loom.20140909t073428-...@post.gmane.org... >I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'b

Passing a list into a list .append() method

2014-09-08 Thread JBB
I have a list with a fixed number of elements which I need to grow; ie. add rows of a fixed number of elements, some of which will be blank. e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', ''], ... ] This is a reduced representation of a larger list-of-li

Re: append method

2012-05-23 Thread Chris Kaynor
On Wed, May 23, 2012 at 12:42 PM, Dave Angel wrote: > On 05/23/2012 03:13 PM, Emile van Sebille wrote: >> A design decision -- there's currently a mix of methods that return >> themselves and not.  Mostly is appears to me that mutables modify in >> place without returning self and immutables retur

Re: append method

2012-05-23 Thread Dave Angel
On 05/23/2012 03:13 PM, Emile van Sebille wrote: > On 5/23/2012 5:23 AM 水静流深 said... >> >>> s=[1,2,3] >> >>> s.append(5) >> >>> s >> [1, 2, 3, 5] >> >>> s=s.append(5) >> >>> s >> >>> print s >> None >> >> why can't s=s.append(5) > > It could, but it doesn't. > > >> ,what is the reason? > > >

Re: append method

2012-05-23 Thread Emile van Sebille
On 5/23/2012 5:23 AM 水静流深 said... >>> s=[1,2,3] >>> s.append(5) >>> s [1, 2, 3, 5] >>> s=s.append(5) >>> s >>> print s None why can't s=s.append(5) It could, but it doesn't. ,what is the reason? A design decision -- there's currently a mix of methods that return themselves and not

Re: append method

2012-05-23 Thread Karl Knechtel
On Wed, May 23, 2012 at 8:23 AM, 水静流深 <1248283...@qq.com> wrote: s=[1,2,3] s.append(5) s > [1, 2, 3, 5] s=s.append(5) s print s > None > > why can't  s=s.append(5)  ,what is the reason? For the same reason that you don't see `[1, 2, 3, 5]` immediately after doing `s.a

Re: append method

2012-05-23 Thread Jean-Michel Pichavant
wrote: >>> s=[1,2,3] >>> s.append(5) >>> s [1, 2, 3, 5] >>> s=s.append(5) >>> s >>> print s None why can't s=s.append(5) ,what is the reason? Because the append method returns None, not the object. It modifies the object in

append method

2012-05-23 Thread ????????
>>> s=[1,2,3] >>> s.append(5) >>> s [1, 2, 3, 5] >>> s=s.append(5) >>> s >>> print s None why can't s=s.append(5) ,what is the reason?-- http://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't python's list append() method return the list itself?

2010-07-16 Thread John Nagle
On 7/13/2010 4:22 AM, Gregory Ewing wrote: John Nagle wrote: Arguably, if a function just does a "return", it should be an error to try to use its return value. It's been suggested at least once before that the default return value for a function should be some special value that raises an exc

Re: Why doesn't python's list append() method return the list itself?

2010-07-14 Thread Nathan Rice
The better question is, do I ever use them? Thinking back over the code I've written in the last couple of years, I would say probably two or three times (mostly in unit tests). I've had to code around string's sequence behavior DOZENS of times. Is it nifty that strings can be sliced like that?

Re: Why doesn't python's list append() method return the list itself?

2010-07-13 Thread Aahz
[Original not available on my swerver, responding here] >On 7/11/10 10:03 PM, Nathan Rice wrote: >> >> Yeah, I long ago filed the in place place in the same folder as >> strings-as-sequences, all() returning True for an empty iterable and any >> returning True rather than the thing which triggered

Re: Why doesn't python's list append() method return the list itself?

2010-07-13 Thread Gregory Ewing
John Nagle wrote: Arguably, if a function just does a "return", it should be an error to try to use its return value. It's been suggested at least once before that the default return value for a function should be some special value that raises an exception if you try to do anything with it exc

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread John Nagle
On 7/11/2010 5:24 PM, Steven D'Aprano wrote: On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/language

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread dhruvbird
On Jul 12, 4:20 pm, Hrvoje Niksic wrote: > dhruvbird writes: > > No, I meant x.append(4) > > Except that I want to accomplish it using slices. > > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > > way?) > > It seems that you've found a way to do so, so why do you need ano

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread Nathan Rice
Stephen: I'm not adverse to being able to do that, but the number of times that I've wanted to do that is greatly outweighed by the number of times I've had to pass a function "(somestring,)" or call "if isinstance(foo, basestring): ..." to avoid producing a bug. The more abstract and adaptive th

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread Hrvoje Niksic
dhruvbird writes: > No, I meant x.append(4) > Except that I want to accomplish it using slices. > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > way?) It seems that you've found a way to do so, so why do you need another way? Are you after elegance? Efficiency? Brevi

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread dhruvbird
On Jul 12, 5:30 am, News123 wrote: > dhruvbird wrote: > > > On a side note, is there any other way to append to a list using > > slices (apart from the one below): > > x[len(x):len(x)] = [item to append] > > dy you mean > x.extend([1,2,3]) No, I meant x.append(4) Except that I want to accomplish

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Chris Rebert
On Sun, Jul 11, 2010 at 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > all() returning True for an empty iterable If you weren't taught about vacuous truth (or even identity elements) in Discrete Mathematics, someone fscked up. Said behavior is t

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Stephen Hansen
On 7/11/10 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > strings-as-sequences, all() returning True for an empty iterable and any > returning True rather than the thing which triggered it. You know, the latter two I can see an argument for, and co

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Nathan Rice
Yeah, I long ago filed the in place place in the same folder as strings-as-sequences, all() returning True for an empty iterable and any returning True rather than the thing which triggered it. Almost always annoying and worked around, but that's the price you pay for the other nice stuff :) It j

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Raymond Hettinger
On Jul 11, 8:59 am, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? Because Guido thinks that having those methods return None is the best way to communicate that the underlying object

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread News123
dhruvbird wrote: > > On a side note, is there any other way to append to a list using > slices (apart from the one below): > x[len(x):len(x)] = [item to append] dy you mean x.extend([1,2,3]) ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Steven D'Aprano
On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? I found this link > (http://code.google.com/edu/languages/google-python- class/lists.html) > wh

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread dhruvbird
On Jul 11, 9:19 pm, Thomas Jollans wrote: > On 07/11/2010 05:59 PM, dhruvbird wrote: > > > Why doesn't python's list append() method return the list itself? For > > that matter, even the reverse() and sort() methods? > > I found this link (http://code.goog

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread MRAB
Thomas Jollans wrote: On 07/11/2010 05:59 PM, dhruvbird wrote: Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/languages/google-python- class/lists.html) which sug

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Antoine Pitrou
On Sun, 11 Jul 2010 08:59:06 -0700 (PDT) dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.htm

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Thomas Jollans
On 07/11/2010 06:28 PM, Nathan Rice wrote: > Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) > > Though TBH sometimes get annoyed at this behavior myself. There are a > lot of people who are very vocal in support of returning none, and it > makes sense in some ways. Since reversed returns

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Nathan Rice
Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) Though TBH sometimes get annoyed at this behavior myself. There are a lot of people who are very vocal in support of returning none, and it makes sense in some ways. Since reversed returns an iterator though, it makes this code horrible and

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Thomas Jollans
On 07/11/2010 05:59 PM, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.html) which suggest

Why doesn't python's list append() method return the list itself?

2010-07-11 Thread dhruvbird
Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/languages/google-python- class/lists.html) which suggests that this is done to make sure that the programmer understand