Re: Consistency in Python

2006-08-26 Thread Hendrik van Rooyen
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote, oder schrieb, of het geskryf: | Hendrik van Rooyen schrieb: | > Hi, | > | > for S where S is a Standard Python type: | > The slice notation S[n] returns either: | > The n'th element of S, or | > The value of the dictionary entry who

Re: Consistency in Python

2006-08-26 Thread Hendrik van Rooyen
"Paul Boddie" <[EMAIL PROTECTED]> Wrote: | Hendrik van Rooyen wrote: | > | > There seems to be no common methods such as- | > "prepend" - for adding something to the beginning | > "append" - for adding something to the end | > "insert[j]" - for adding something somewhere in the middle

Re: Consistency in Python

2006-08-25 Thread Fredrik Lundh
Brendon Towle wrote: >> b) http://pyfaq.infogami.com/why-doesn-t-list-sort-return-the-sorted-list >>(this also explains how to handle your specific use case) > > Well, I posted working code, so I thought it should have been obvious > that I knew how to handle my use case, and was (am) lookin

Re: Consistency in Python

2006-08-25 Thread Fredrik Lundh
Brendon Towle wrote: > My third response is that it's *always* possible to shoot yourself in > the foot. Protecting a naive user from one particular metatarsal > projectile insertion at the expense of letting the power-user write more > concise code seems a bad tradeoff to me -- but, I'm not in

Re: Consistency in Python

2006-08-25 Thread Terry Reedy
  "Brendon Towle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]... Message: 3 Date: Fri, 25 Aug 2006 15:28:46 +0200 From: "Fredrik Lundh" <[EMAIL PROTECTED]> Subject: Re: Consistency in Python Brendon Towle wr

Re: Consistency in Python

2006-08-25 Thread Brendon Towle
Message: 3 Date: Fri, 25 Aug 2006 15:28:46 +0200 From: "Fredrik Lundh" <[EMAIL PROTECTED]> Subject: Re: Consistency in Python Brendon Towle wrote: So, my question is: Someone obviously thought that it was wise and proper to require the longer versions that I write above. Why? a

Re: Consistency in Python

2006-08-25 Thread Fredrik Lundh
Brendon Towle wrote: > So, my question is: Someone obviously thought that it was wise and > proper to require the longer versions that I write above. Why? a) maybe they had a working carriage return key ? b) http://pyfaq.infogami.com/why-doesn-t-list-sort-return-the-sorted-list (this also exp

Re: Consistency in Python

2006-08-25 Thread Brendon Towle
Date: 25 Aug 2006 04:22:37 -0700From: "Paul Boddie" <[EMAIL PROTECTED]>Subject: Re: Consistency in PythonTo: python-list@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Paul McGuire wrote: But with mutators that return self, a client could write any of these:b

Re: Consistency in Python

2006-08-25 Thread Paul Boddie
Paul McGuire wrote: > > There's nothing wrong with returning self from a mutator. This was a common > idiom in Smalltalk (the syntax for this was "^self", which was probably the > most common statement in any Smalltalk program), and permitted the chaining > of property mutators into a single line,

Re: Consistency in Python

2006-08-25 Thread Paul McGuire
"Paul Boddie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Moreover, append and insert return > no result because the change occurs within an existing object - if you > were to return a reference to the changed object, it would be the same > reference as the one you already had.

Re: Consistency in Python

2006-08-25 Thread Paul Boddie
Hendrik van Rooyen wrote: > > There seems to be no common methods such as- > "prepend" - for adding something to the beginning > "append" - for adding something to the end > "insert[j]" - for adding something somewhere in the middle > > Or have I missed something ? [...] > BTW - I und

Re: Consistency in Python

2006-08-25 Thread Diez B. Roggisch
Hendrik van Rooyen schrieb: > Hi, > > for S where S is a Standard Python type: > The slice notation S[n] returns either: > The n'th element of S, or > The value of the dictionary entry whose key is n. > > This is beautiful because as a programmer you don't have to worry what S

Consistency in Python

2006-08-25 Thread Hendrik van Rooyen
Hi, for S where S is a Standard Python type: The slice notation S[n] returns either: The n'th element of S, or The value of the dictionary entry whose key is n. This is beautiful because as a programmer you don't have to worry what S is... (and as an aside - This consistency h

Re: Question about consistency in python language

2005-09-11 Thread Terry Reedy
"Robert Kern" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > In many, many fonts 'l' and '1' look close enough to be easily mistaken > for one another In the default font used by Outlook Express, displayed on my 1078x786 screen, the only difference I can see, using a magnifying g

Re: Question about consistency in python language

2005-09-11 Thread Robert Kern
James wrote: [James Stroud wrote:] >>Also, you shouldn't use "1", I mean "l", as a variable name. It gets confusing >>because "l", I mean "1", looks a lot like "1", I mean "l". > > I have seen the same warnning above significantly several times. > Is this problem originally came from the similari

Re: Question about consistency in python language

2005-09-11 Thread Kay Schluehr
Steve Holden wrote: > Kay Schluehr wrote: > > Mike Meyer wrote: > > > > > >>Yes, but the function "sorted" is more useful than a list method > >>"sorted" in a duck typing language. > > > > > > I don't see what this has to do with "duck typing"? sorted() is simply > > a generic function accepting d

Re: Question about consistency in python language

2005-09-11 Thread James
> Also, you shouldn't use "1", I mean "l", as a variable name. It gets confusing > because "l", I mean "1", looks a lot like "1", I mean "l". I have seen the same warnning above significantly several times. Is this problem originally came from the similarities between 'l' and '1' or from bad looki

Re: Question about consistency in python language

2005-09-10 Thread Steve Holden
Kay Schluehr wrote: > Mike Meyer wrote: > > >>Yes, but the function "sorted" is more useful than a list method >>"sorted" in a duck typing language. > > > I don't see what this has to do with "duck typing"? sorted() is simply > a generic function accepting different types. I'm not aware that >

Re: Question about consistency in python language

2005-09-09 Thread Kay Schluehr
Terry Reedy wrote: > "Kay Schluehr" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > On the other hand there exists no sorted() method for tuples or lists > > like join() for strings but it is implemented as a function in Python24 > > that returns a new sorted container. I consider

Re: Question about consistency in python language

2005-09-09 Thread Kay Schluehr
Mike Meyer wrote: > Yes, but the function "sorted" is more useful than a list method > "sorted" in a duck typing language. I don't see what this has to do with "duck typing"? sorted() is simply a generic function accepting different types. I'm not aware that sorted() requires a specific interface

Re: Question about consistency in python language

2005-09-09 Thread Terry Reedy
"Kay Schluehr" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On the other hand there exists no sorted() method for tuples or lists > like join() for strings but it is implemented as a function in Python24 > that returns a new sorted container. I consider this as an > inconsistency

Re: Question about consistency in python language

2005-09-09 Thread Mike Meyer
"Kay Schluehr" <[EMAIL PROTECTED]> writes: > If you define > sep = "" sep.join(["d","o","g"]) > "dog" sep > '' > > sep is preserved and a new "dog" string is generated. Since sep is > immutable there is no way to manipulate it inplace. > > On the other hand there exists no sorted() m

Re: Question about consistency in python language

2005-09-09 Thread Mike Meyer
Dave Benjamin <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: >> Dave Benjamin <[EMAIL PROTECTED]> writes: >>>Python is actually quite consistent in this regard: methods that >>>modify an object in-place return None; >> Um, no. list.pop comes to mind as an immediate counterexample. It may >> be the

Re: Question about consistency in python language

2005-09-08 Thread Kay Schluehr
[EMAIL PROTECTED] wrote: > Let's say I define a list of pairs as follows: > >>l = [('d', 3), ('a', 2), ('b', 1)] > > Can anyone explain why this does not work? > >>h = {}.update(l) > > and instead I have to go: > >>h = {} > >>h.update(l) > to initialize a dictionary with the given list of pairs? >

Re: Question about consistency in python language

2005-09-08 Thread Erik Max Francis
Dave Benjamin wrote: > Mike Meyer wrote: >> Dave Benjamin <[EMAIL PROTECTED]> writes: >> >>>Python is actually quite consistent in this regard: methods that >>>modify an object in-place return None; >> >> Um, no. list.pop comes to mind as an immediate counterexample. It may >> be the only one...

Re: Question about consistency in python language

2005-09-08 Thread Dave Benjamin
Mike Meyer wrote: > Dave Benjamin <[EMAIL PROTECTED]> writes: > >>Python is actually quite consistent in this regard: methods that >>modify an object in-place return None; > > Um, no. list.pop comes to mind as an immediate counterexample. It may > be the only one... I'm sure there are counterexa

Re: Question about consistency in python language

2005-09-08 Thread Mike Meyer
Dave Benjamin <[EMAIL PROTECTED]> writes: > Python is actually quite consistent in this regard: methods that > modify an object in-place return None; Um, no. list.pop comes to mind as an immediate counterexample. It may be the only one... http://www.mired.org/home/mwm/ Indepe

Re: Question about consistency in python language

2005-09-08 Thread Dave Benjamin
[EMAIL PROTECTED] wrote: > Let's say I define a list of pairs as follows: > >>>l = [('d', 3), ('a', 2), ('b', 1)] > > > Can anyone explain why this does not work? > >>>h = {}.update(l) > > > and instead I have to go: > >>>h = {} >>>h.update(l) > > to initialize a dictionary with the given l

Re: Question about consistency in python language

2005-09-08 Thread Bengt Richter
On 8 Sep 2005 16:03:12 -0700, [EMAIL PROTECTED] wrote: >Let's say I define a list of pairs as follows: >>>l = [('d', 3), ('a', 2), ('b', 1)] > >Can anyone explain why this does not work? >>>h = {}.update(l) > >and instead I have to go: >>>h = {} >>>h.update(l) >to initialize a dictionary with the

Re: Question about consistency in python language

2005-09-08 Thread Sam Pointon
update updates the dictionary in place - it actually returns None, not the updated dict. However, you can construct a dictionary from a list of (key, value) pairs using dict(list). Example: >>>l = [('foo', 'bar'), ('baz', 'qig')] >>>d = dict(l) >>>print d {'foo': 'bar', 'baz': 'qig'} -- http://m

Re: Question about consistency in python language

2005-09-08 Thread James Stroud
This is the difference between mutable and immutable types. In this sense it is consistent. If you want to do the former in one shot: h = dict(l) Also, you shouldn't use "1", I mean "l", as a variable name. It gets confusing because "l", I mean "1", looks a lot like "1", I mean "l". James

Question about consistency in python language

2005-09-08 Thread lechequier
Let's say I define a list of pairs as follows: >>l = [('d', 3), ('a', 2), ('b', 1)] Can anyone explain why this does not work? >>h = {}.update(l) and instead I have to go: >>h = {} >>h.update(l) to initialize a dictionary with the given list of pairs? when an analagous operation on strings works