I have a list of dictionaries like this:
temp = [
{
"item": "apple",
"id": 1
},
{
"item": "ball",
"id": 2
},
{
"item": "cake",
"id": 3
}
]
I want two lists:
["apple", "ball", "cake"]
[1, 2, 3]
Can we do this using list comprehension?
I have done like this:
list_item=[]
list_id=[]
for val in temp:
list_item.append(val["item"])
list_id.append(val["id"])