kd.kontext.filter_by_path#
- kauldron.kontext.filter_by_path(
- obj: Any,
- path: str | tuple[str, ...] | kauldron.kontext.paths.AbstractPath,
Filters a context by a path.
This function returns a subset of the context. This only supports dict, list and tuple types. Non-matching list items are removed.
Example:
assert kontext.filter_by_path( { 'a': { 'b': { 'c': 1, 'c1': 1, 'c2': 1, }, 'b2': { 'c': {'d': 1}, 'c1': {'d': 1}, 'c2': {'d': 1}, }, }, }, '**.c', # Select only the `c` keys. ) == { 'a': { 'b': { 'c': 1, }, 'b2': { 'c': {'d': 1}, }, }, }
- Parameters:
obj – The context to filter.
path – The path to filter by.
- Returns:
A subset of the context.