Map function with lambda in a list of Python dictionaries

Asked

Viewed 283 times

0

Good evening, I’m taking the data via API and turning it into a . JSON to record in a list:. Inside this info is a list of dictionaries called custom_fields, so I used map with lambda function to pick up the values:

info = r.json()

gravar=[]
for infos in info['tickets']:
        gravar.append((infos['url'],
                    infos['id'],
                    infos['created_at'],
                    infos['status'],
                    infos['requester_id'],
                    infos['collaborator_ids'],
                    infos['tags'],
                    map(lambda t: t["id"], infos['custom_fields']),
                    map(lambda v: v["values"], infos['custom_fields'])
    )) 

print(gravar[0])

Instead of returning the values, it is returning in this way:

...<map object at 0x000001B3B27CEFD0>, <map object at 0x000001B3B27F0048>)

How do I list the elements within the dictionaries of this list?

1 answer

0

I was able to solve using the list function:

list(map(lambda t: t["id"], infos['custom_fields'])),
list(map(lambda v: v["value"], infos['custom_fields']))

return:

...,[360022972013, 360022962034, 360022975213], [None, None, None])

Browser other questions tagged

You are not signed in. Login or sign up in order to post.