QUERY · ISSUE
reversed() does not work as expected for ucollections.OrderedDict
py-core
Since I expected OrderedDict to be a doubly linked list, and I needed the last element I wanted to use reversed to grab the last element in the OrderedDict, it didn't work as expected so I wrote some test code.
from collections import OrderedDict
from random import randrange
source = list(set(randrange(2000) for _ in range(2000)))
od = OrderedDict([(k, 1) for k in source])
print(list(od) == source) # True
# CPython: True
# MicroPython: KeyError or False
last_key = next(reversed(od))
print(last_key == source[-1])
# CPython: True
# MicroPython: KeyError
print(list(reversed(source)) == list(reversed(od))) # True
Sure enough, it does not work expected. Producing either KeyErrors or just bad values.
CANDIDATE · ISSUE
OrderedDict doesn't test for equality
OrderedDicts can't be compared;
>>> from ucollections import OrderedDict
>>> a=OrderedDict()
>>> a['a']=23
>>> a['b']=25
>>> b=OrderedDict()
>>> b['a']=23
>>> b['b']=25
>>> a==b
False