about sort and dictionary

rurpy at yahoo.com rurpy at yahoo.com
Tue Nov 22 11:53:07 EST 2005


Fredrik Lundh wrote:
> bonono at gmail.com 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
> > 1
> > 1
> > 2
> > 3
> >
> really?  wouldn't
>
>     3
>     2
>     1
>     3
>     2
>     1
>
> make a lot more sense ?

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.
I used reverse() and sort() a couple time and of course read
the docs before I did.  I noted they do the change inplace, and
don't find rememering that to be a terrible burden.  Actually, I
get rather annoyed by the comment that they return None "as
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 help me with my memory.




More information about the Python-list mailing list