Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Getting list values with afilter #141

Open
Assignees
Labels

Description

I might be missing something, but why does afilter not get dict/list values? Any specific reason for that?

data = [
 {
 "choices": [
 "Charity",
 "Cooperative",
 "Corporation",
 "Educational institution",
 "Public entity",
 "International organisation"
 ]
 },
 {
 "items": [
 {
 "choices": "country"
 }
 ],
 }
]
def afilter(x):
 print x
 return True
res = dpath.util.search(data, "**/choices", yielded=True, afilter=afilter)

Running this results in ...

country
('1/items/0/choices', 'country')

Or to phrase it differently: how can I search for elements which include "Charity"? My current solution looks like this:

res = dpath.util.search(data, "**/choices", yielded=True)
for item in res:
 val = dpath.util.get(data, item[0])
 if "Charity" in val:
 print item[0]

But that would be much simpler if afilter also gets the list of the first element.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /