Re: about sort and dictionary

2005-11-24 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: do things right is my fundamental beef with Python. Dispite claims, I don't believe Python's designers have a monopoly on the definition of right. This hammer is stupid. It's very uncomfortable, and it's not hard and heavy enough to get the nails into the wall. It

Re: about sort and dictionary

2005-11-24 Thread Magnus Lycka
Alex Martelli wrote: I think you mean volatile or mutable rather than transient? transient is not a keyword in C++, while both volatile and mutable are, with different semantics. Anyway, C++'s 'const' is a mess both theoretical AND practical. I'm told Ruby's object-freezing works better

Re: about sort and dictionary

2005-11-24 Thread Alex Martelli
Magnus Lycka [EMAIL PROTECTED] wrote: ... I think you mean volatile or mutable rather than transient? transient ... Right, volatile it is. It's really great that I can program so much Python now that I forget my C++! :) Thanks Alex (both for reminding me of forgotten C++ syntax and for

Re: about sort and dictionary

2005-11-24 Thread Björn Lindström
Magnus Lycka [EMAIL PROTECTED] writes: As I understand it, Ruby's ! isn't quite like procedure in Pascal, or not const in C/C++, but rather a marker for surprising behaviour, In my experience, ! is used in Ruby much the same way as it is in Scheme, signifying that a method/function is called

Re: about sort and dictionary

2005-11-24 Thread Magnus Lycka
Alex Martelli wrote: I don't think these headaches and difficulties justify dumping the whole field of reasoning about programs, nor the subfield of PbC. The concept of immutable is really just a tiny corner of these fields, and it's a long way from being the hardest or most problematic one

Re: about sort and dictionary

2005-11-24 Thread Alex Martelli
Magnus Lycka [EMAIL PROTECTED] wrote: Alex Martelli wrote: I don't think these headaches and difficulties justify dumping the whole field of reasoning about programs, nor the subfield of PbC. The concept of immutable is really just a tiny corner of these fields, and it's a long way from

Re: about sort and dictionary

2005-11-23 Thread Sion Arrowsmith
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: OKB (not okblacke) wrote: Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: [ ... ] so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in

Re: about sort and dictionary

2005-11-23 Thread [EMAIL PROTECTED]
Sion Arrowsmith wrote: 1. sort() in place makes sense in terms of space, and is not completely unintuitive. 2. reverse() should do what sort() does. 3. The inexperienced user is most likely to expect the above code to print 3 2 1 3 2 1, and is more likely to have difficulty

Re: about sort and dictionary

2005-11-23 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: a reminder that the change is inplace. How arrogant! While I'm sure the designers had kindly intentions. my memory, though bad, is not that bad, and I object to being forced to write code that is more clunky than need be, because the designers thought they needed to

Re: about sort and dictionary

2005-11-23 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: Alex Martelli wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... intuitive seems to be a very subjective matter, depends on once background etc :-) That's a strong point of Ruby, actually -- allowing an exclamation mark at the end of a method name, which

Re: about sort and dictionary

2005-11-23 Thread Alex Martelli
Magnus Lycka [EMAIL PROTECTED] wrote: ... indicate that the method is a mutator. So, you can have a.reverse [NOT mutating a since no !] _and_ a.reverse! [mutating a]. Probably too much of a change even for Python 3000, alas... but, it DOES make it obvious when an object's getting mutated,

Re: about sort and dictionary

2005-11-23 Thread Neil Hodgson
Magnus Lycka: Except when it isn't obvious. What constitutes mutation of an object? C++ handles this with 'const', and lets the programmer cheat by using transient member variables, since there are cases when you actually want to mutate objects a little, but claim that you don't... Ruby

Re: about sort and dictionary

2005-11-23 Thread rurpy
Magnus Lycka wrote: [EMAIL PROTECTED] wrote: a reminder that the change is inplace. How arrogant! While I'm sure the designers had kindly intentions. my memory, though bad, is not that bad, and I object to being forced to write code that is more clunky than need be, because the

Re: about sort and dictionary

2005-11-23 Thread Alex Martelli
Neil Hodgson [EMAIL PROTECTED] wrote: Magnus Lycka: Except when it isn't obvious. What constitutes mutation of an object? C++ handles this with 'const', and lets the programmer cheat by using transient member variables, since there are cases when you actually want to mutate objects a

Re: about sort and dictionary

2005-11-23 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: do things right is my fundamental beef with Python. Dispite claims, I don't believe Python's designers have a monopoly on the definition of right. I think raymond's post more correctly described it. Rather than do things right, it is more the world view of python, just

Re: about sort and dictionary

2005-11-23 Thread Mike Meyer
[EMAIL PROTECTED] (Alex Martelli) writes: Neil Hodgson [EMAIL PROTECTED] wrote: Ruby uses '!' not for mutation but to indicate surprising or destructive mutation. If it was placed on all mutators, code would be full of '!'s. '!' is less common on methods that modify the receiver than on

Re: about sort and dictionary

2005-11-22 Thread Duncan Booth
Magnus Lycka wrote: Actually, I guess it's possible that sorted() is done so that it works like below, but I don't think pre-sorted() versions of Python support keyword arguments to list.sort() anyway... def sorted(l, *p, **kw): s=l[:];s.sort(*p, **kw);return s One part you missed, sorted

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Magnus Lycka wrote: sorted_l = l.sort() and while sorted_l would contain what one might expect, it would in fact just be another name referencing exactly the same sorted list as l, and it would probably be surprising that l was also sorted, and that subsequent changes would show up in both

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as it was. a=[1,2,3] I expect it to

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as it was. a=[1,2,3] I

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: Since python's '=' is just name binding and that most objects(other than those like int/float/string?) are mutable, I don't quite understand why this is a gotcha that is so worrying. a = [1,2,3] a.sorted() b = a even an entry level python programmer can't expect

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as it was. a=[1,2,3] I expect it to print 3 2

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as it was. a=[1,2,3]

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
Still don't see why even you ask it again. fyi, I'm not [EMAIL PROTECTED] , and I've never, as far I know, posted from readfreenews.net /F -- http://mail.python.org/mailman/listinfo/python-list

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: Still don't see why even you ask it again. fyi, I'm not [EMAIL PROTECTED] , and I've never, as far I know, posted from readfreenews.net I have no idea what you are talking about. I read this list through Google's group and I saw two of the same post. Google

Re: about sort and dictionary

2005-11-22 Thread rurpy
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as it was. a=[1,2,3]

Re: about sort and dictionary

2005-11-22 Thread Steven D'Aprano
On Tue, 22 Nov 2005 08:53:07 -0800, rurpy wrote: I am not a complete newb at python, but I am still pretty new. I too thought immediately that the output should be 3,2,1, 1,2,3. What you are saying is that a.reverse() should *both* change a in place *and* return a reference to the same list.

Re: about sort and dictionary

2005-11-22 Thread OKB (not okblacke)
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: There are four possibilities for a construction like list.sort(): (1) sort the list in place and return a reference to the same list; (2) sort the list in place and return a copy of the same list; (3) sort the list in place and return None; (4) don't sort in place and

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
OKB (not okblacke) wrote: Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it

Re: about sort and dictionary

2005-11-22 Thread rurpy
Steven D'Aprano [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Tue, 22 Nov 2005 08:53:07 -0800, rurpy wrote: I am not a complete newb at python, but I am still pretty new. I too thought immediately that the output should be 3,2,1, 1,2,3. What you are saying is that

Re: about sort and dictionary

2005-11-22 Thread Mike Meyer
[EMAIL PROTECTED] writes: I think this is just another (admittedly minor) case of Python's designers using Python to enforce some idea of programming style purity. You say that as if it were a bad thing. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Mike Meyer wrote: [EMAIL PROTECTED] writes: I think this is just another (admittedly minor) case of Python's designers using Python to enforce some idea of programming style purity. You say that as if it were a bad thing. I would say interesting thing. As it seems that quite some people

Re: about sort and dictionary

2005-11-22 Thread rurpy
Mike Meyer wrote: [EMAIL PROTECTED] writes: I think this is just another (admittedly minor) case of Python's designers using Python to enforce some idea of programming style purity. You say that as if it were a bad thing. Well, there are many languages that promote a specific style of

Re: about sort and dictionary

2005-11-22 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... intuitive seems to be a very subjective matter, depends on once background etc :-) That's a strong point of Ruby, actually -- allowing an exclamation mark at the end of a method name, which conventionally is always used to indicate that the

Re: about sort and dictionary

2005-11-22 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... language, yea, I guess I think it's bad. A general purpose language should strive to support as wide a varity of styles as possible. Definitely NOT Python's core design principle, indeed the reverse of it. But this is getting rather off-topic. Yep. If you

Re: about sort and dictionary

2005-11-22 Thread rurpy
Alex Martelli wrote: [EMAIL PROTECTED] wrote: ... language, yea, I guess I think it's bad. A general purpose language should strive to support as wide a varity of styles as possible. Definitely NOT Python's core design principle, indeed the reverse of it. Priciples are fine if not

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... intuitive seems to be a very subjective matter, depends on once background etc :-) That's a strong point of Ruby, actually -- allowing an exclamation mark at the end of a method name, which conventionally is always

Re: about sort and dictionary

2005-11-22 Thread rurpy
Alex Martelli wrote: [EMAIL PROTECTED] wrote: ... language, yea, I guess I think it's bad. A general purpose language should strive to support as wide a varity of styles as possible. Definitely NOT Python's core design principle, indeed the reverse of it. Priciples are fine if not

Re: about sort and dictionary

2005-11-22 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: Steven D'Aprano wrote: There are four possibilities for a construction like list.sort(): (1) sort the list in place and return a reference to the same list; (2) sort the list in place and return a copy of the same list; (3) sort the list in place and return None; (4)

Re: about sort and dictionary

2005-11-21 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: most built-in function/method don't return the object but None. This I believe is the language creator's preference for everything being explicit. The list methods .sort() and .reverse() don't create copies, but rather change the existing object. The reson for this is

Re: about sort and dictionary

2005-11-21 Thread George Sakkis
Shi Mu wrote: Got confused by the following code: a [6, 3, 1] b [4, 3, 1] c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} c[2].append(b.sort()) c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? In python 2.4, you can use the sorted() builtin

Re: about sort and dictionary

2005-11-21 Thread George Sakkis
Shi Mu wrote: Got confused by the following code: a [6, 3, 1] b [4, 3, 1] c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} c[2].append(b.sort()) c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? In python 2.4, you can use the sorted() builtin

about sort and dictionary

2005-11-20 Thread Shi Mu
Got confused by the following code: a [6, 3, 1] b [4, 3, 1] c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} c[2].append(b.sort()) c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? b.sort() b [1, 3, 4] --

Re: about sort and dictionary

2005-11-20 Thread [EMAIL PROTECTED]
Shi Mu wrote: Got confused by the following code: a [6, 3, 1] b [4, 3, 1] c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} c[2].append(b.sort()) c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? b.sort() b [1, 3, 4] most built-in

Re: about sort and dictionary

2005-11-20 Thread Eric Jacoboni
Shi Mu [EMAIL PROTECTED] writes: #why c can not append the sorted b?? Because sort() doesn't return anything? According to the library reference: 7) The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list. To remind you that they