libb.MutableDict

class MutableDict[source]

Bases: dict

An ordered dictionary with additional insertion methods.

Extends the standard dictionary with methods to insert items before or after existing keys. Relies on Python 3.7+ dictionary implementation which preserves insertion order.

insert_before(key, new_key, val)[source]

Insert new_key:value into dict before key.

Example:

>>> d = MutableDict({'a': 1, 'b': 2, 'c': 3})
>>> d.insert_before('b', 'x', 10)
>>> list(d.keys())
['a', 'x', 'b', 'c']
>>> d['x']
10
insert_after(key, new_key, val)[source]

Insert new_key:value into dict after key.

Example:

>>> d = MutableDict({'a': 1, 'b': 2, 'c': 3})
>>> d.insert_after('a', 'x', 10)
>>> list(d.keys())
['a', 'x', 'b', 'c']
>>> d['x']
10