相关疑难解决方法(0)

将Python字典转换为List

可能重复:
如何将Python字典转换为元组列表?

我正在尝试将Python字典转换为Python列表,以便执行一些计算.

#My dictionary
dict = {}
dict['Capital']="London"
dict['Food']="Fish&Chips"
dict['2012']="Olympics"

#lists
temp = []
dictList = []

#My attempt:
for key, value in dict.iteritems():
    aKey = key
    aValue = value
    temp.append(aKey)
    temp.append(aValue)
    dictList.append(temp) 
    aKey = ""
    aValue = ""
Run Code Online (Sandbox Code Playgroud)

这是我的尝试......但我无法弄清楚什么是错的?

python dictionary list

180
推荐指数
7
解决办法
56万
查看次数

标签 统计

dictionary ×1

list ×1

python ×1