-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Open
Labels
py-coreRelates to py/ directory in sourceRelates to py/ directory in source
Description
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.
Metadata
Metadata
Assignees
Labels
py-coreRelates to py/ directory in sourceRelates to py/ directory in source