这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@oda
Copy link
Owner

@oda oda commented Apr 12, 2025

This PR updates OrderedDict’s C implementation, and adds insert_before, insert_after, and swap, which are discussed in the thread below.
https://discuss.python.org/t/insert-swap-get-by-index-for-ordereddict/52375/5

from collections import OrderedDict
d = OrderedDict({i:i for i in range(10)})
d = OrderedDict(a=1, b=2, c=3)
a = d.copy()
a.insert_before('b', 'x', 0)
print(dict(a))
b = d.copy()
b.insert_after('b', 'x', 0)
print(dict(b))
d.swap('a', 'c')
print(dict(d))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants