Python 基于字典列表中的不同键获取多个列表

Python 基于字典列表中的不同键获取多个列表,python,python-3.x,list,Python,Python 3.x,List,我有一个这样的字典列表: temp = [ { "item": "apple", "id": 1 }, { "item": "ball", "id": 2 }, { "item": "cake", "id": 3 } ] list_item=[] list_id=[] for val in temp: list_item.append(val[

我有一个这样的字典列表:

temp = [
    {
        "item": "apple",
        "id": 1
    },
    {
        "item": "ball",
        "id": 2
    },
    {
        "item": "cake",
        "id": 3
    }
]
list_item=[]
list_id=[]
for val in temp:
    list_item.append(val["item"])
    list_id.append(val["id"])
我想要两份清单:

["apple", "ball", "cake"]
[1, 2, 3]
我们可以使用列表理解来实现这一点吗

我是这样做的:

temp = [
    {
        "item": "apple",
        "id": 1
    },
    {
        "item": "ball",
        "id": 2
    },
    {
        "item": "cake",
        "id": 3
    }
]
list_item=[]
list_id=[]
for val in temp:
    list_item.append(val["item"])
    list_id.append(val["id"])

使用字典键
l1
中存储值,使用
id
l2
中存储值

q=[
{
“物品”:“苹果”,
“id”:1
},
{
“物品”:“球”,
“id”:2
},
{
“项目”:“蛋糕”,
“id”:3
}
]
l1=[dic['item']表示q中的dic]
l2=[dic['id']表示q中的dic]
在单个循环中:

l1,l2=[],[]
对于q中的dic:
l1.追加(dic['item'])
l2.追加(dic['id'])

使用字典键
将值存储在
l1
中,使用
id
将值存储在
l2

q=[
{
“物品”:“苹果”,
“id”:1
},
{
“物品”:“球”,
“id”:2
},
{
“项目”:“蛋糕”,
“id”:3
}
]
l1=[dic['item']表示q中的dic]
l2=[dic['id']表示q中的dic]
在单个循环中:

l1,l2=[],[]
对于q中的dic:
l1.追加(dic['item'])
l2.追加(dic['id'])
你可以这样试试

见此:

你可以这样试试


看到这个:

你好。你能分享一下你到目前为止所做的事情吗?这能回答你的问题吗?不是真的@SushanthI更新了描述@balajiambresh谢谢。我相信你已经看过苏拉杰的帖子了。你好。你能分享一下你到目前为止所做的事情吗?这能回答你的问题吗?不是真的@SushanthI更新了描述@balajiambresh谢谢。我相信你现在已经看过苏拉杰的帖子了。我们可以用单for循环吗?我们可以用单for循环吗?