Skip to content

mapping

quickdict.mapping module.

Mapping of dictionaries.

qd_map(p: Callable[[V], W], m: Mapping[K, V]) -> dict[K, W]

Return a dict with p applied to the values.

Python implementation.

Source code in quickdict\mapping\_pymapping.py
20
21
22
23
24
25
26
27
28
29
30
def qd_map(p:Callable[[V],W], m:Mapping[K,V]) -> dict[K,W]:
    """Return a `dict` with `p` applied to the values.

    Python implementation.
    """
    if not callable(p):
        raise TypeError('p must be callable')
    if not isinstance(m, Mapping):
        raise TypeError('m must be a mapping')

    return {k:p(v) for k, v in m.items()}

qd_imap(p: Callable[[V], V], m: MutableMapping[K, V]) -> MutableMapping[K, V]

Apply p to the values.

Python implementation.

Source code in quickdict\mapping\_pymapping.py
32
33
34
35
36
37
38
39
40
41
42
43
44
def qd_imap(p:Callable[[V],V], m:MutableMapping[K,V]) -> MutableMapping[K,V]:
    """Apply `p` to the values.

    Python implementation.
    """
    if not callable(p):
        raise TypeError('p must be callable')
    if not isinstance(m, MutableMapping):
        raise TypeError('m must be a mutable mapping')

    for k, v in m.items():
        m[k] = p(v)
    return m

qd_pos(m: Mapping[K, V]) -> dict[K, V]

Return a dict with the unary plus operator applied to the values.

Python implementation.

Source code in quickdict\mapping\_pymapping.py
47
48
49
50
51
52
53
54
55
def qd_pos(m:Mapping[K,V]) -> dict[K,V]:
    """Return a `dict` with the unary plus operator applied to the values.

    Python implementation.
    """
    if not isinstance(m, Mapping):
        raise TypeError('m must be a mapping')

    return {k:+v for k, v in m.items()}

qd_ipos(m: MutableMapping[K, V]) -> MutableMapping[K, V]

Apply the unary plus operator to the values.

Python implementation.

Source code in quickdict\mapping\_pymapping.py
57
58
59
60
61
62
63
64
65
66
67
def qd_ipos(m:MutableMapping[K,V]) -> MutableMapping[K,V]:
    """Apply the unary plus operator to the values.

    Python implementation.
    """
    if not isinstance(m, MutableMapping):
        raise TypeError('m must be a mutable mapping')

    for k, v in m.items():
        m[k] = +v
    return m

qd_neg(m: Mapping[K, V]) -> dict[K, V]

Return a dict with negated values.

Python implementation.

Source code in quickdict\mapping\_pymapping.py
70
71
72
73
74
75
76
77
78
def qd_neg(m:Mapping[K,V]) -> dict[K,V]:
    """Return a `dict` with negated values.

    Python implementation.
    """
    if not isinstance(m, Mapping):
        raise TypeError('m must be a mapping')

    return {k:-v for k, v in m.items()}

qd_ineg(m: MutableMapping[K, V]) -> MutableMapping[K, V]

Negate the values.

Python implementation.

Source code in quickdict\mapping\_pymapping.py
80
81
82
83
84
85
86
87
88
89
90
def qd_ineg(m:MutableMapping[K,V]) -> MutableMapping[K,V]:
    """Negate the values.

    Python implementation.
    """
    if not isinstance(m, MutableMapping):
        raise TypeError('m must be a mutable mapping')

    for k, v in m.items():
        m[k] = -v
    return m