Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from collections import namedtuple
2from typing import Any, Mapping
5def to_namedtuple(name: str, dictionary: Mapping[str, Any]) -> Any:
6 """Convert a dictionary to a NamedTuple.
8 Useful for generating inputs to functions that expect NamedTuples.
10 Examples:
11 >> to_namedtuple("PandasRow", {"a": 10, "b": 20})
12 PandasRow(a=10, b=20)
13 """
14 return namedtuple(name, dictionary.keys())(**dictionary)