我有这本字典:
{'Francisco Partners': [45000000],
'Bpifrance': [45000000, 15000000,87000000,15000000,...],
...}
我写了这段代码来获取它,遍历每个键并获取对应值(即数组)的最大值,中位数和最小值
srs = [["name", "max", "med", "min"]]
for key, value in dct:
srs_row = []
srs_row.append(key)
srs_row.append(max(value))
srs_row.append(median(value))
srs_row.append(min(value))
srs.append(srs_row)
运行程序时,出现此错误,指向“ for ...”行:
ValueError: too many values to unpack (expected 2)
如果不是数组,机器将尝试输入什么“值”? 因此,有没有一种方法可以将值作为数组卸载,并在之后进行迭代?
最好
答案 0 :(得分:1)
您需要使用dictionary.items
来遍历dct
for key, value in dct.items():
#Code