move to end, in Python 3.2 Really?

Antoine Pitrou solipsis at pitrou.net
Tue Jan 18 07:46:22 EST 2011


On Mon, 17 Jan 2011 21:20:48 -0800 (PST)
Raymond Hettinger <python at rcn.com> wrote:
> On Jan 17, 6:51 pm, nn <prueba... at latinmail.com> wrote:
> > ...But the api on this baffles me a bit:
> >
> > >>> d = OrderedDict.fromkeys('abcde')
> > >>> d.move_to_end('b', last=False)
> > >>> ''.join(d.keys)
> >
> > 'bacde'
> >
> > I understand that "end" could potentially mean either end, but would
> > "move_to_end" and "move_to_beginning" not have been clearer?
> 
> The default (and normal usage) is to move an item to the last
> position.
> So, od.move_to_end(k) becomes a fast equivalent to v=d.pop(k)
> followed by d[k]=v.
> 
> The less common usage of moving to the beginning is done with
> last=False.  This parallels the existing API for od.popitem():

Well I have to agree that moving to the beginning using move_to_end()
with a "last" argument looks completely bizarre and unexpected.
"Parallels popitem()" is not really convincing since popitem() doesn't
have "end" its name.

> Those were the design considerations.  Sorry you didn't like the
> result.

Design considerations? Where were they discussed?

Regards

Antoine.





More information about the Python-list mailing list