Message181184
Please don't rush to make patches. It isn't even clear that this is a good idea.
AFAICT, none of the many extant implementation of ordered dictionaries in any language currently implement a rotate operation.
FWIW, the iter() and move_to_end() methods are likely your best bet for implementing a rotate function using the current API and without doing any ordered dictionary key lookups:
>>> from collections import OrderedDict
>>> from itertools import islice
>>>
>>> def rotate(d, n):
# quick demo
if n > 0:
for k in list(islice(d, n)):
d.move_to_end(k)
elif n < 0:
for k in list(islice(reversed(d), -n)):
d.move_to_end(k, 0)
>>> d = collections.OrderedDict.fromkeys('abcdefghijk')
>>> list(d)
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
>>> rotate(d, 3)
>>> list(d)
['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'a', 'b', 'c']
>>> rotate(d, -3)
>>> list(d)
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'] |
|
Date |
User |
Action |
Args |
2013-02-02 17:44:53 | rhettinger | unlink | issue17100 messages |
2013-02-02 17:38:44 | rhettinger | set | recipients:
+ rhettinger, pitrou, eric.snow, Ramchandra Apte, serhiy.storchaka |
2013-02-02 17:38:44 | rhettinger | set | messageid: <1359826724.85.0.257742832191.issue17100@psf.upfronthosting.co.za> |
2013-02-02 17:38:44 | rhettinger | link | issue17100 messages |
2013-02-02 17:38:44 | rhettinger | create | |
|