about sort and dictionary
bonono at gmail.com
bonono at gmail.com
Tue Nov 22 05:21:10 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 have no idea. That is my expectation. I don't know yours.
My interpretation of it is :
a got reversed then I consume it one by one
a got reversed again then I consume it one by one
Because I expect a being a mutable object, anything works on it(not
just object method, but even other functions) is by default has side
effect, unless otherwise stated, like copy/deepcopy.
More information about the Python-list
mailing list