def deep_pluck(collection, path): """Like pluck but works with deep paths. Args: collection (list|dict): list of dicts path (str|list): collection's path to pluck Returns: list: plucked list Example: >>> deep_pluck([[[0, 1]], [[2, 3]], [[4, 5]]], '0.1') [1, 3, 5] >>> deep_pluck([{'a': {'b': 1}}, {'a': {'b': 2}}], 'a.b') [1, 2] >>> deep_pluck([{'a': {'b': [0, 1]}}, {'a': {'b': [2, 3]}}], 'a.b.1') [1, 3] .. versionadded:: 2.2.0 """ return map_(collection, pyd.deep_property(path))
def deep_pluck(collection, path): """Like pluck but works with deep paths. Args: collection (list|dict): list of dicts path (str|list): collection's path to pluck Returns: list: plucked list Example: >>> deep_pluck([[[0, 1]], [[2, 3]], [[4, 5]]], '0.1') [1, 3, 5] >>> deep_pluck([{'a': {'b': 1}}, {'a': {'b': 2}}], 'a.b') [1, 2] >>> deep_pluck([{'a': {'b': [0, 1]}}, {'a': {'b': [2, 3]}}], 'a.b.1') [1, 3] .. versionadded:: 2.2.0 """ return map_(collection, pyd.deep_property(path))
def test_deep_property(case, arg, expected): assert _.map_(arg, _.deep_property(case)) == expected