New submission from Antoine Pitrou:

It can be useful to rotate an OrderedDict (for example when managing a circular 
playlist). I haven't found any efficient way to do so from user code, without 
poking at the internals.

Actually, I envision three methods:

 OrderedDict.rotate(self, n):

   rotate n steps to the right (similarly to deque.rotate())

 OrderedDict.rotate_at(self, key):

   rotate so that the given key ends up in first position

 OrderedDict.rotate_after(self, key):

   rotate so that the given key ends up in last position

(rotate_at, rotate_after could be merged in a single method with a "last" 
argument, if deemed more elegant)

Note: another solution to the playlist problem would be to have insert_after() 
and insert_before() methods.

----------
messages: 181086
nosy: pitrou, rhettinger
priority: normal
severity: normal
status: open
title: rotating an ordereddict
type: enhancement
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17100>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to