datapad.fields.get#
- datapad.fields.get(key, default=None)#
Constructs a function
F(data)to get a field-value given a field-key from a list or dict. If a field-key is not present in data, returndefaultvalue. This function is commonly used as a keying-function forSequence.map,Sequence.sort,Sequence.groupby, andSequence.join.Examples
In the examples below, assume
datais an element or row coming from aSequence.>>> F = get('a', 'foobar') >>> F({'a': 1}) 1 >>> F({'b': 2}) 'foobar'
>>> F = get(0, "default") >>> F([10]) 10
>>> F = get(1, "default") >>> F([10]) 'default'