我有一份清单
key_list = ['m.title', 'm.studio', 'm.gross', 'm.year']
cols = [
['Titanic', 'The Lord of the Rings: The Return of the King', 'Toy Story 3'],
['Par.', 'NL', 'BV'],
['2186.8', '1119.9', '1063.2'],
['1997', '2003', '2010']
]
Run Code Online (Sandbox Code Playgroud)
我想构建一个字典table_dict,其键是key_list的元素,值是cols的各个子列表.
我目前的代码如下:
i = 0
for key in key_list:
table_dict[key] = cols[i]
i = i + 1
return table_dict
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到错误,但当我运行它时,我得到:
dict[key] = cols[i]
IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)