dicts
Starlark module for working with dicts.
dicts.add(*dictionaries, **kwargs)
Returns a new dict that has all the entries of the given dictionaries.
If the same key is present in more than one of the input dictionaries, the last of them in the argument list overrides any earlier ones. If you want to be alerted when there is an override see dicts.unique_add.
This function is designed to take zero or one arguments as well as multiple dictionaries, so that it follows arithmetic identities and callers can avoid special cases for their inputs: the sum of zero dictionaries is the empty dictionary, and the sum of a single dictionary is a copy of itself.
Example:
dicts.add({'language': 'larky', 'company': 'vgs'}, {'version': '0.1.0'})
{'language': 'larky', 'company': 'vgs', 'version': '0.1.0'}
Parameters:
*dictionaries - zero or more dictionaries to be added.
**kwargs - additional dictionary passed as keyword args.
Returns: a new dict that has all the entries of the given dictionaries.
dicts.only(dictionary, *keys)
Returns: a new dict that only has the keys you specified.
Example:
dicts.only({'language': 'larky', 'company': 'vgs', 'version': '0.1.0'}, 'company', 'version')
{'company': 'vgs', 'version': '0.1.0'}
Parameters:
dictionary - the dictionary to operate on.
*keys – the keys in the dictionary you want to keep.
Returns: a new dict that only has the keys you specified.
dicts.unique_add(*dictionaries, **kwargs)
Like dicts.add but fails when there is a duplicate key.
Parameters:
*dictionaries - zero or more dictionaries to be added.
**kwargs - additional dictionary passed as keyword args.
Returns: a new dict that has all the entries of the given dictionaries.
dicts.without(dictionary, *keys)
Returns: a new dict that has all the keys except the ones you specified.
Example:
dicts.without({'language': 'larky', 'company': 'vgs', 'version': '0.1.0'}, 'version', 'company')
{'language': 'larky'}
Parameters:
dictionary - the dictionary to operate on.
*keys - the keys in the dictionary you want removed.
Returns: a new dict that has all the keys except the ones you specified.
Last updated