mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
py/objdict: Fix popitem for ordered dicts.
The popitem method wasn't implemented for ordered dicts and would result in an invalid state. Fixes issue #5956.
This commit is contained in:
committed by
Damien George
parent
347c8917dc
commit
57fce3bdb2
@@ -24,3 +24,23 @@ d["abc"] = 123
|
||||
print(len(d))
|
||||
print(list(d.keys()))
|
||||
print(list(d.values()))
|
||||
|
||||
# pop an element
|
||||
print(d.popitem())
|
||||
print(len(d))
|
||||
print(list(d.keys()))
|
||||
print(list(d.values()))
|
||||
|
||||
# add an element after popping
|
||||
d["xyz"] = 321
|
||||
print(len(d))
|
||||
print(list(d.keys()))
|
||||
print(list(d.values()))
|
||||
|
||||
# pop until empty
|
||||
print(d.popitem())
|
||||
print(d.popitem())
|
||||
try:
|
||||
d.popitem()
|
||||
except:
|
||||
print('empty')
|
||||
|
||||
Reference in New Issue
Block a user