0

In Python, given a dict in input as follows:

input = {
    'foo': 'bar'
}

which glom spec should I use to transform it into an array with a single item?

spec = ?
glom(input, spec)
# ['bar']

I can't find any reference for such a transformation in glom documentation

Thanks

4

1 回答 1

0

Based on their documentation, you can utilize lambda as a part of the spec argument:

import glom
input = {'foo': 'bar'}
foo = glom.glom(input, ('foo', lambda t: [t]))
print(foo)
>>> ['bar']
于 2021-12-15T16:12:53.917 回答