【发布时间】:2019-04-21 08:05:51
【问题描述】:
我正在尝试定义一个函数,该函数从与指定索引相关的字典 studentPerf(非常大,但我给出了前三项)的键中返回数据元素列表,其中每个可能的值是只列出一次。例如,如果字典中的键是 [('John',2),('Julie',2),('John',3),('John',1),('Julie',1) ,('Julie',3)],那么这个函数应该返回索引 0 的 ['John','Julie'] 和索引 1 的 [1,2,3]。
到目前为止,我一直收到错误“ValueError:解压的值太多(预期为 2)”
studentPerf = {('Jeffery','male','junior'):[0.81,0.75,0.74,0.8],
('Able','male','senior'):[0.87,0.79,0.81,0.81],
('Don','male','junior'):[0.82,0.77,0.8,0.8]}
def select(key, index):
for key, index in studentPerf.keys():
print(index)
select(0,1)
【问题讨论】:
标签: python dictionary dictionary-comprehension