-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide example of list of dictionaries and filtering by intermediate key #42
Comments
dpath: >>> import dpath.util
>>> d = {'x': [{'a': 5, 'b': 2}, {'a': 6, 'b': 4}]}
>>> dpath.util.values(d, 'x')
[[{'a': 5, 'b': 2}, {'a': 6, 'b': 4}]]
>>> dpath.util.values(d, 'x/*')
[{'a': 5, 'b': 2}, {'a': 6, 'b': 4}]
>>> dpath.util.values(d, 'x/*/**/a')
[5, 6] funcy: >>> from funcy import get_in
>>> get_in(d, ["x"])
[{'a': 5, 'b': 2}, {'a': 6, 'b': 4}]
>>> from funcy import pluck
>>> pluck("a", get_in(d, ["x"]))
[5, 6] |
@xhh2a answered your first question nicely, so I'll focus on the second.
This is not explicitly documented (not every use case is in the documentation). This is currently a 2 step process (though a more elegant solution is currently being discussed in #40 ).
I'm going to make a master ticket for documentation updates and link this from there; closing for now. |
I think @binki was asking why this works:
… rather than complaining that it doesn't work and asking what to do instead, which is what @xhh2a answered. But it does work, and if you just had a single example showing a Right now, there is such an example, but it's wrong: the |
Say I have this:
and I want to list all the values of
a
. I cannot get from the README that I would use:Also, how can I look up the value of
'b'
for when'a'
is 6, for example? Is there a place to look for documentation (that could be linked from the README?) Am I not looking for docs in the right place just because I’m unfamiliar with python? ;-)Thanks for any help or doc updates!
The text was updated successfully, but these errors were encountered: