LEARN VOID / DATA & BEHAVIOR
Dictionaries
Associate keys and values while preserving insertion order.
Complete program for the synchronous entry adapter. The result below is the returned integer.
func entry(extra_notebooks: i32) -> i32:
var supplies: {string: i32} = {"notebooks": 2, "pens": 5}
supplies["notebooks"] += extra_notebooks
supplies["folders"] = 3
return supplies["notebooks"]Create a typed mapping
{string: i32} maps supply names to quantities. The literal starts with two notebooks and five pens. Looking up supplies["notebooks"] yields the quantity for that known key.
Update and insert
Compound assignment adds the input to an existing notebook quantity; input 5 gives 7. Assigning supplies["folders"] = 3 inserts a new key. Lookup and compound assignment require the key to exist; missing keys raise a runtime failure. Use contains(key) when presence is uncertain.
Explore membership and order
Iteration uses for quantity, name in supplies: in insertion order; reverse visits the reverse order. Replacing a value preserves its key’s position. remove(key) reports whether removal happened, while clear() empties the mapping. Assignment shares dictionary identity. A proposed get API is not available.