所以我收到错误: RuntimeError:字典在迭代期间更改了大小。
我有 2 个矩阵,一个用于 Xbox 信息,一个用于 PS4 信息 第一个函数根据 Xbox 矩阵创建字典。它查看矩阵内的每个列表,并从每个列表中获取信息并将其添加到字典中。第二个函数获取已经制作的字典 def create_dictionary_xbox并添加到其中。我正在尝试使其打印出如下内容:
{genre:{game:[info], game:[info]}}
这是我的代码:
def create_dictionary_xbox(lists_of_data):
dictionary = {}
for list_ in lists_of_data:
game = list_[0]
genre = list_[2]
if genre not in dictionary:
dictionary[genre] = {game : list_[3:]}
elif genre in dictionary:
(dictionary[genre])[game] = list_[3:]
return dictionary
def create_dictionary_PS4(lists_of_data,dictionary):
for list_ in lists_of_data:
game = list_[0]
genre = list_[2]
for key in dictionary:
if genre not in dictionary:
dictionary[genre] = {game : list_[3:]}
elif genre in dictionary:
(dictionary[genre])[game] = list_[3:]
return dictionary
子衿沉夜
相关分类