46db0366b8
this implementation is hoped to be smaller. (feather_m4_express/fr fits unlike the other PR; approximate savings ~600 bytes) Minor difference to standard Python: A `dict` object has a `move_to_end` method. However, calling this method always results in TypeError. Implementing it this way means that the method table can still be shared between OrderedDict and builtin dict. Closes #4408.
45 lines
830 B
Python
45 lines
830 B
Python
try:
|
|
from collections import OrderedDict
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
try:
|
|
{'a': None}.move_to_end('a')
|
|
except (TypeError, AttributeError):
|
|
print("Exception")
|
|
|
|
d = OrderedDict(a=1, b=2, c=3)
|
|
d.move_to_end('a')
|
|
print(list(d.items()))
|
|
|
|
d = OrderedDict(a=1, b=2, c=3)
|
|
d.move_to_end('b')
|
|
print(list(d.items()))
|
|
|
|
d = OrderedDict(a=1, b=2, c=3)
|
|
d.move_to_end('c')
|
|
print(list(d.items()))
|
|
|
|
try:
|
|
d.move_to_end('x')
|
|
except KeyError:
|
|
print("KeyError")
|
|
|
|
d = OrderedDict(a=1, b=2, c=3)
|
|
d.move_to_end('a', last=False)
|
|
print(list(d.items()))
|
|
|
|
d = OrderedDict(a=1, b=2, c=3)
|
|
d.move_to_end('b', last=False)
|
|
print(list(d.items()))
|
|
|
|
d = OrderedDict(a=1, b=2, c=3)
|
|
d.move_to_end('c', last=False)
|
|
print(list(d.items()))
|
|
|
|
try:
|
|
d.move_to_end('x', last=False)
|
|
except KeyError:
|
|
print("KeyError")
|