β All terms Β· Data structures
NamedTuple
Tuple with named fields β accessed by `t.x` instead of `t[0]`. `typing.NamedTuple` is the modern form; gives you type hints + immutability for free.
class Point(NamedTuple):
x: int
y: intLearn this interactively:
Open lesson lesson-105 βRelated β Data structures
List comprehensionInline syntax for building a list from another iterable, with optional filter: `β¦Dict comprehensionSame as list comp, but builds a dict: `{k: v for k, v in pairs}`.TupleOrdered immutable sequence. Use for fixed-size records and as dict keys.SetUnordered collection of unique hashable values. O(1) membership check.DictionaryHash map from keys to values. Insertion order preserved since Python 3.7.IterableAnything you can loop over with `for`. Lists, tuples, sets, dicts, strings, fileβ¦