set
Builtin index · Collections & strings
result =get(d, key)/set(d, key, value)
Input: d, key · Output: result
What it is
d is a Dict; key is a Str/number; value (for set) is any value. get returns the stored value (any type) or none if key is absent. set returns a new Dict with that entry written — it does not modify d in place, so assign the result.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = get(d, key) / set(d, key, value) | d Dictd is a Dict.key Str or numberkey is a Str/number. | result Dict | Returns the stored value (any type) or none from get, and a new Dict from set. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
d = dict(["a", "b"], [1, 2])
d = set(d, "c", 3)
print(get(d, "b")) # 2
print(keys(d)) # ("a", "b", "c")
print(values(d)) # (1, 2, 3)
print(items(d)) # (("a", 1), ("b", 2), ("c", 3))
print(has_key(d, "c")) # true
print(has_key(d, "z")) # false
output
2
("a", "b", "c")
(1, 2, 3)
(("a", 1), ("b", 2), ("c", 3))
true
falsefrom collections-strings
See also
get — documented in the same entry.