datapad.fields.asdict#
- datapad.fields.asdict(keys=None)#
Constructs a function that will convert a list into a dict using the given keys. The returned function will have the signature:
F(data:list) -> dict
This function is commonly used in conjunction with
datapad.Sequence.map()to manipulate structured sequence data.- Parameters:
keys (list) – A list of strings or any other valid hashable type that will be associated with each element of the input
datalist. If keys is None,F(data)will use the indices of each list field as the key.
Examples
Convert list to dict using pre-defined keys:
>>> data = [1, 2, 3] >>> F = asdict(['a', 'b', 'c']) >>> F(data) {'a': 1, 'b': 2, 'c': 3}
Convert list to dict using list indices as keys:
>>> data = [1, 2, 3] >>> F = asdict() >>> F(data) {0: 1, 1: 2, 2: 3}