Map function with lambda in a list of Python dictionaries
Good night, I'm taking the data via API and turning it into one .JSON to write to a list:. Inside lsta info there is a list of dictionaries called custom_fields, so I used map with lambda function to get 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 this way:
...<map object at 0x000001B3B27CEFD0>, <map object at 0x000001B3B27F0048>)
How do I list the elements within the dictionaries of that list?
0
1 answers
I managed 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])
0
Author: Maursb, 2019-07-31 00:13:22