Python 尝试从字典列表加载到列表列表

Python 尝试从字典列表加载到列表列表,python,list,dictionary,Python,List,Dictionary,我试图在Python2.7中从字典项列表加载到列表。数据当前看起来像以下20行: [{'professional:xp': '100', 'personal:power': 'fly', 'personal:hero': 'yes', 'custom:color': 'black', 'professional:name': 'batman'}, {'professional:xp': '86', 'personal:power': 'think', 'personal:hero': 'no',

我试图在Python2.7中从字典项列表加载到列表。数据当前看起来像以下20行:

[{'professional:xp': '100', 'personal:power': 'fly', 'personal:hero': 'yes', 'custom:color': 'black', 'professional:name': 'batman'}, {'professional:xp': '86', 'personal:power': 'think', 'personal:hero': 'no', 'custom:color': 'grey', 'professional:name': 'gandalf'}, ...]
我想这样做:

[[100, 'fly', 'yes', 'black', 'batman'][86, 'think', 'no', 'grey', 'gandalf']...]
我尝试了很多不同的循环方式,但都没有结果

i = -1
j = -1
scanList = []
joinList = [[]]

for item in scanList:
    i = i+1
    for k, v in item.iteritems():
        j= j+1
        joinList[i][j].append(v)

我的想法是通过嵌套循环加载列表(首先我不知道我的I和j是否在正确的位置,但我可以处理这个问题)。我一直在避免索引错误,我不知道是否应该在之前初始化列表列表?

现在是学习列表理解的好时机。还要注意,
[dict].values()
可以方便地返回字典中的值列表

joinList = [d.values() for d in scanList]

请注意,在Python 3.x中
values()
返回一个视图对象,该对象必须显式转换为列表:

# Python 3.x version
joinList = [list(d.values()) for d in scanList]

您可以使用获取字典的值。现在,您必须迭代字典并调用字典上的值:

[d.values() for d in scan_list]
您可以使用以下代码:

for item in scanList:
    list = []
    for key, value in item.iteritems():
        list.append(value)
    joinlist.append(list)
输出

[['yes', 'black', 'batman', 'fly', '100'], ['no', 'grey', 'gandalf', 'think', '86']]

这是低效的使用列表理解这是错误的<代码>值()不返回列表。我建议进行编辑。@alec935 OP使用的是Python 2.7,它确实使用了Python 2.7。你可能用的是3.x。啊,我错了。哇,你让它看起来很简单。一旦我完成了这方面的工作,我马上要学习更多关于列表理解的知识。非常感谢。
[['yes', 'black', 'batman', 'fly', '100'], ['no', 'grey', 'gandalf', 'think', '86']]