Issue
I have a json in the following format and I just want to save 2 parts of it. But I get it as separate characters. Can you please help me?
for data in results['results']:
dictionary = dict(zip("title:", data['title']))
dictionary = dict(zip("uuid:", data['uuid']))
Json
results": [
{
"title": "subject1",
"ja_pub_yyyy": 1395,
"uuid": "86ae6",
"external_link": null,
"fulltext_status": 1,
},
{
"title": "subject2",
"ja_pub_yyyy": 1395,
"uuid": "86ae6",
"external_link": null,
"fulltext_status": 1,
}
]
new_result
results": [
{
"title": "subject1",
"id": "86ae6",
},
{
"title": "subject2",
"id": "86ae6",
}]
Solution
You are not creating each dict
properly. It is more simple:
new_result = []
for data in results['results']:
l = ((k,data[k]) for k in ("title","uuid"))
dictionary = dict(l)
new_result.append(dictionary)
I have demonstrated collecting each dictionary
.
Answered By - quamrana
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.