Re: Puzzled by list-appending behavior

2011-05-27 Thread Ethan Furman
Prasad, Ramit wrote: I have to say, I do like Python's lack of keywords for these things I thought True/False were among the list of keywords in Python 3.x ? Or are those the only keywords? http://docs.python.org/py3k/reference/lexical_analysis.html#keywords False class finally

RE: Puzzled by list-appending behavior

2011-05-27 Thread Prasad, Ramit
>I have to say, I do like Python's lack of keywords for these things I thought True/False were among the list of keywords in Python 3.x ? Or are those the only keywords? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone

Re: Puzzled by list-appending behavior

2011-05-27 Thread MRAB
On 27/05/2011 07:34, Tim Roberts wrote: MRAB wrote: I'd just like to point out that it's a convention, not a rigid rule. Reminds me of the catch-phrase from the first Pirates of the Caribbean movie: "It's more of a guideline than a rule." Much like the Zen of Python. -- http://mail.python.

Re: Puzzled by list-appending behavior

2011-05-26 Thread Tim Roberts
MRAB wrote: > >I'd just like to point out that it's a convention, not a rigid rule. Reminds me of the catch-phrase from the first Pirates of the Caribbean movie: "It's more of a guideline than a rule." -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.python.org/mailm

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Angelico
On Fri, May 27, 2011 at 1:52 PM, Steven D'Aprano wrote: > Because "lst" is not a real word. To native readers of languages derived > from Latin or Germany, such as English, it is quite a strange "word" > because it has no vowel. In addition, it looks like 1st (first). Contrived examples are alway

Re: Puzzled by list-appending behavior

2011-05-26 Thread Steven D'Aprano
On Fri, 27 May 2011 13:24:24 +1000, Chris Angelico wrote: > On Fri, May 27, 2011 at 11:59 AM, Steven D'Aprano > wrote: >> def get(list, object): >>    """Append object to a copy of list and return it.""" return list + >>    [object] >> >> For one or two line functions, I think that's perfectly re

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Angelico
On Fri, May 27, 2011 at 11:59 AM, Steven D'Aprano wrote: > def get(list, object): >    """Append object to a copy of list and return it.""" >    return list + [object] > > For one or two line functions, I think that's perfectly reasonable. > Anything more than that, I'd be getting nervous. But ev

Re: Puzzled by list-appending behavior

2011-05-26 Thread Steven D'Aprano
On Thu, 26 May 2011 11:27:35 -0700, John Ladasky wrote: > On May 25, 9:46 pm, Uncle Ben wrote: > >> list = [1,2,3] > > Somewhat unrelated, but... is it a good idea to name your list "list"? > Isn't that the name of Python's built-in list constructor method? > > Shadowing a built-in has contri

Re: Puzzled by list-appending behavior

2011-05-26 Thread Terry Reedy
On 5/26/2011 11:58 AM, MRAB wrote: On 26/05/2011 06:17, Chris Rebert wrote: list.remove(), list.sort(), and list.extend() similarly return None rather than the now-modified list. I'd just like to point out that it's a convention, not a rigid rule. Sometimes it's not followed, for example, dic

RE: Puzzled by list-appending behavior

2011-05-26 Thread Prasad, Ramit
>> And why do you insist on calling an instance of list, "list"? Even a >> human reader will confuse which is which. What you are showing is an >> example how confusing things become when a keyword (list) is >> over-written (with list instance). > (Minor note: 'list' is not a keyword (if it were,

Re: Puzzled by list-appending behavior

2011-05-26 Thread Terry Reedy
On 5/26/2011 3:18 AM, Algis Kabaila wrote: And why do you insist on calling an instance of list, "list"? Even a human reader will confuse which is which. What you are showing is an example how confusing things become when a keyword (list) is over-written (with list instance). (Minor note: 'lis

Re: Puzzled by list-appending behavior

2011-05-26 Thread John Ladasky
On May 25, 9:46 pm, Uncle Ben wrote: > list = [1,2,3] Somewhat unrelated, but... is it a good idea to name your list "list"? Isn't that the name of Python's built-in list constructor method? Shadowing a built-in has contributed to more than one subtle bug in my code, and I've learned to avoid

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Angelico
On Fri, May 27, 2011 at 1:58 AM, MRAB wrote: > I'd just like to point out that it's a convention, not a rigid rule. > Sometimes it's not followed, for example, dict.setdefault. dict.setdefault is more like dict.get but it also stores the result. It's probably more a name issue than a protocol iss

Re: Puzzled by list-appending behavior

2011-05-26 Thread MRAB
On 26/05/2011 06:17, Chris Rebert wrote: On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: In playing with lists of lists, I found the following: (In 3.1, but the same happens also in 2.7) list = [1,2,3] list.append ( [4,5,6] ) Note the lack of output after this line. This indicates that li

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Rebert
On Thu, May 26, 2011 at 12:23 AM, Chris Angelico wrote: > On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: >> >> Ben Finney has already answered the main question > > Giving credit where credit's due, it was more Chris Rebert's post that > answered the question. Sorry Chris! Eh, one can't

Re: Puzzled by list-appending behavior

2011-05-26 Thread Uncle Ben
On May 26, 12:46 am, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) > x = list > x   -> >     [1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = lis

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Angelico
On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: > > Ben Finney has already answered the main question Giving credit where credit's due, it was more Chris Rebert's post that answered the question. Sorry Chris! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Angelico
On Thu, May 26, 2011 at 2:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] Ben Finney has already answered the main question, but as a side point, I would generally avoid creating a variable called '

Re: Puzzled by list-appending behavior

2011-05-26 Thread Algis Kabaila
On Thursday 26 May 2011 14:46:45 Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) > x = list > x -> > [1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1

Re: Puzzled by list-appending behavior

2011-05-25 Thread Chris Rebert
On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) Note the lack of output after this line. This indicates that list.append([4,5,6]) returned None. C

Re: Puzzled by list-appending behavior

2011-05-25 Thread Ben Finney
Uncle Ben writes: > Can someone explain this to me? Yes, the documentation for that function (‘list.append’) can explain it. In short: if a method modifies the instance, that method does not return the instance. This policy holds for the built-in types, and should be followed for user-defined t