Skip to content

SortedDict

Bases: BaseSortedDict[K, V]


              flowchart TD
              pyochain.collections._sorted._dict.SortedDict[SortedDict]
              pyochain.collections._sorted._dict.BaseSortedDict[BaseSortedDict]
              pyochain.abc._mappings.PyoMutableMapping[PyoMutableMapping]
              pyochain.abc._mappings.PyoMapping[PyoMapping]
              pyochain.abc._collection.PyoCollection[PyoCollection]
              pyochain.collections._sorted._core.SortedCollection[SortedCollection]
              pyochain.abc._sequences.PyoReversible[PyoReversible]
              pyochain.abc._iterable.PyoIterable[PyoIterable]
              pyochain.abc._collection.PyoContainer[PyoContainer]
              pyochain.abc._collection.PyoSized[PyoSized]
              pyochain.abc._mixins.Checkable[Checkable]
              pyochain.abc._mixins.Fluent[Fluent]
              pyochain.abc._mixins.Pipe[Pipe]
              pyochain.abc._mixins.Tap[Tap]

                              pyochain.collections._sorted._dict.BaseSortedDict --> pyochain.collections._sorted._dict.SortedDict
                                pyochain.abc._mappings.PyoMutableMapping --> pyochain.collections._sorted._dict.BaseSortedDict
                                pyochain.abc._mappings.PyoMapping --> pyochain.abc._mappings.PyoMutableMapping
                                pyochain.abc._collection.PyoCollection --> pyochain.abc._mappings.PyoMapping
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                


                pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
                

                pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
                




                pyochain.collections._sorted._core.SortedCollection --> pyochain.collections._sorted._dict.BaseSortedDict
                
                pyochain.abc._sequences.PyoReversible --> pyochain.collections._sorted._dict.BaseSortedDict
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._sequences.PyoReversible
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                






              click pyochain.collections._sorted._dict.SortedDict href "" "pyochain.collections._sorted._dict.SortedDict"
              click pyochain.collections._sorted._dict.BaseSortedDict href "" "pyochain.collections._sorted._dict.BaseSortedDict"
              click pyochain.abc._mappings.PyoMutableMapping href "" "pyochain.abc._mappings.PyoMutableMapping"
              click pyochain.abc._mappings.PyoMapping href "" "pyochain.abc._mappings.PyoMapping"
              click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
              click pyochain.collections._sorted._core.SortedCollection href "" "pyochain.collections._sorted._core.SortedCollection"
              click pyochain.abc._sequences.PyoReversible href "" "pyochain.abc._sequences.PyoReversible"
              click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
              click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
              click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
              click pyochain.abc._mixins.Checkable href "" "pyochain.abc._mixins.Checkable"
              click pyochain.abc._mixins.Fluent href "" "pyochain.abc._mixins.Fluent"
              click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
              click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
            

Sorted dict is a MutableMapping whose keys are maintained in sorted order.

The design of sorted dict is simple: a SortedDict uses an internal dict to store items and maintains a sorted list of keys.

Sorted dict keys must be hashable and comparable.

The hash and total ordering of keys must not change while they are stored in the sorted dict.

Sorted dicts may only be compared for equality and inequality.

Optional iterable argument provides an initial sequence of pairs to initialize the sorted dict.

Each pair in the sequence defines the key and corresponding value.

If a key is seen more than once, the last value associated with it is stored in the new sorted dict.

Optional mapping argument provides an initial mapping of items to initialize the sorted dict.

If keyword arguments are given, the keywords themselves, with their associated values, are added as items to the dictionary.

If a key is specified both in the positional argument and as a keyword argument, the value associated with the keyword is stored in the SortedDict.

Sorted dict keys must be hashable, per the requirement for Python's dict.

Keys must also be comparable, per the requirement for sorted lists.

from pyochain.collections import SortedDict

d = {"a": 1, "b": 2}

assert SortedDict([("a", 1), ("b", 2)]) == d
assert SortedDict({"a": 1, "b": 2}) == d
assert SortedDict(a=1, b=2) == d
Source code in pyochain/collections/_sorted/_dict.pyi
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
@final
class SortedDict[K: SupportsHashableAndRichComparison, V](BaseSortedDict[K, V]):
    """Sorted dict is a `MutableMapping` whose keys are maintained in sorted order.

    The design of sorted dict is simple: a `SortedDict` uses an internal `dict` to store items and maintains a sorted list of keys.

    Sorted dict keys must be hashable and comparable.

    The hash and total ordering of keys must not change while they are stored in the sorted dict.

    Sorted dicts may only be compared for equality and inequality.

    Optional iterable argument provides an initial sequence of pairs to initialize the sorted dict.

    Each pair in the sequence defines the key and corresponding value.

    If a key is seen more than once, the last value associated with it is stored in the new sorted dict.

    Optional mapping argument provides an initial mapping of items to initialize the sorted dict.

    If keyword arguments are given, the keywords themselves, with their associated values, are added as items to the dictionary.

    If a key is specified both in the positional argument and as a keyword argument,
    the value associated with the keyword is stored in the `SortedDict`.

    Sorted dict keys must be hashable, per the requirement for Python's `dict`.

    Keys must also be comparable, per the requirement for sorted lists.

    ```python
    from pyochain.collections import SortedDict

    d = {"a": 1, "b": 2}

    assert SortedDict([("a", 1), ("b", 2)]) == d
    assert SortedDict({"a": 1, "b": 2}) == d
    assert SortedDict(a=1, b=2) == d
    ```

    """

    def __init__(
        self, iterable: Iterable[tuple[K, V]] | Mapping[K, V] = (), **kwargs: V
    ) -> None: ...
    @override
    def __or__[T1, T2](self, value: Mapping[K, T2], /) -> SortedDict[K, V | T2]: ...
    @override
    def __ror__[T1, T2](self, value: Mapping[K, T2], /) -> SortedDict[K, V | T2]: ...
    @override
    def __reduce__(self) -> tuple[type[Self], tuple[Dict[K, V]]]: ...
    @override
    def copy(self) -> Self: ...