使用下面的表由表创建字典,我想创建一个字典,水果为键和量作为值使用第一列表作为头部
grades = [['Fruit', 'Apples', 'Bananas', 'Coconut'],
['Jim', '4', '5', '6'],
['Kevin', '7', '8', '10'],
['Clayton', '8', '9', '2']]
例如:
QuantityList['Apples'] == [4,7,8]
我在下面的代码,但我得到一个“'列表'对象不可调用”错误。
num=[y[1:] for y in table[1:]]
fruits = table[0][1:]
QuantityList={y[0]: {int(i) for i in num()} for y in fruits}
print(QuantityList)
有人可以提供一些方向如何解决这个问题吗?
你的例子不一致。什么是“成绩”? – DyZ
@DYZ是真的,表应该被称为“等级” – alfasin
yup yup.my错误。我实际上使用了一个更大的数据集,并且创建了一个示例问题。 – GenXeral