-
Notifications
You must be signed in to change notification settings - Fork 60
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
Question, how to pull items into an array in a spec? #260
Comments
you want the >>> from glom import glom, Fill, T
>>> target = {'a': 1, 'b': 2}
>>> glom(target, Fill([T['a'], T['b']]))
[1, 2]
in the full context: >>> target = { 'a': 1, 'b': 2, 'c': [{ 'd': 3, 'e': 4 }] }
>>> spec = {'my_output': {'a_and_b': Fill([T['a'], T['b']]),
... 'c': ('c', [{'new_d': 'd', 'new_e': 'e'}]) } }
>>> glom(target, spec)
{'my_output': {'a_and_b': [1, 2], 'c': [{'new_d': 3, 'new_e': 4}]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suppose I have a target:
{ 'a': 1, 'b': 2, 'c': [{ 'd': 3, 'e': 4 }] }
how would I write a spec to produce the output:
{ 'my_output': { 'a_and_b': [1, 2], 'c': [{ 'new_d': 3, 'new_e': 4 }] } }
the part I am hung up on, is how to take 'a' and 'b' and get them into an array...
spec = { 'my_output': { 'a_and_b': ['a', 'b'], 'c': ('c', [{'new_d': 'd', 'new_e': 'e'}]) } }
The text was updated successfully, but these errors were encountered: