Skip to content

dict

Dict literals {k: v}, dict(), and methods returning dicts. Insertion order is preserved.

MethodReturnsMeaning
.lengthnumberNumber of pairs, same as len(d). Property: no parens (game-specific convenience)
.keys() / .values() / .items()listKeys / values / (key, value) tuples in insertion order (for k, v in d.items():)
.has(key)booleanMembership test, equivalent to key in d (game-specific convenience)
.get(key, default=None)anyValue or default; never raises for a missing hashable key (unhashable still raises TypeError)
.pop(key, default?)anyRemove and return; raises if missing unless a default is given
.popitem()tupleRemove and return the last inserted pair; raises when empty
.setdefault(key, default=None)anyReturn d[key] if present, else set and return default; useful for grouped collections
.update(other?, **kwargs)NoneMerge entries (dict, iterable of pairs, kwargs, or both), overwriting matching keys
.copy()dictShallow copy (nested mutables shared)
.clear()NoneRemove all entries