Skip to main content

Mojo module

dict

Defines Dict, a collection that stores key-value pairs.

Dict provides an efficient, O(1) amortized average-time complexity for insert, lookup, and removal of dictionary elements. Its implementation closely mirrors Python's dict implementation:

  • Performance and size are heavily optimized for small dictionaries, but can scale to large dictionaries.

  • Insertion order is implicitly preserved. Iteration over keys, values, and items have a deterministic order based on insertion.

  • For more information on the Mojo Dict type, see the Mojo Dict manual. To learn more about using Python dictionaries from Mojo, see Python types in Mojo.

Key elements must implement the KeyElement trait composition, which includes Movable, Hashable, Equatable, and Copyable. The Copyable requirement will eventually be removed.

Value elements must be Copyable and Movable. As with KeyElement, the Copyable requirement for value elements will eventually be removed.

See the Dict docs for more details.

Aliases

KeyElement

comptime KeyElement = Copyable & Movable & Hashable & Equatable

A trait composition for types which implement all requirements of dictionary keys. Dict keys must minimally be Copyable, Movable, Hashable, and Equatable.

Structs

  • Dict: A container that stores key-value pairs.
  • DictEntry: Store a key-value pair entry inside a dictionary.
  • OwnedKwargsDict: Container used to pass owned variadic keyword arguments to functions.

Was this page helpful?