We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
For example,
data = {"items": ["a", {"c": 1}]} assert benedict(data).keypaths() == [ "items", "items[0]", "items[1]", "items[1].c" ]
In my use case, I have a regular expression as a filter for keypaths, the filtered keypaths are passed to subset() to make a new filtered dict.
subset()
import re filter = "items[\d+].name" data = {"items": [{"name": "a", "value": "b"}, {"name": "c", "value": "d"}]} b_data = benedict(data) filtered_keypaths = [kp for kp in b_data.keypaths() if re.fullmatch(filter, kp)] filtered_data = b_data.subset(filtered_keypaths) assert filtered_data == {"items": [{"name": "a"}, {"name": "b"}]}
Just like what map() works in the functional programming.
The text was updated successfully, but these errors were encountered:
This is really an interesting feature.
I think that subset could be improved to accept also a regex to do exactly what you need with just 1 line of code.
subset
Sorry, something went wrong.
Added indexes support to keypaths method. #13
4ad0f94
@momocow with 0.21.0 version you can retrieve keypaths including indexes:
0.21.0
data = {"items": ["a", {"c": 1}]} kps = benedict(data).keypaths(indexes=True) assert kps == [ "items", "items[0]", "items[1]", "items[1].c" ]
fabiocaccamo
No branches or pull requests
For example,
In my use case, I have a regular expression as a filter for keypaths, the filtered keypaths are passed to
subset()
to make a new filtered dict.For example,
Just like what map() works in the functional programming.
The text was updated successfully, but these errors were encountered: