到目前为止,这是我的程序。我需要做的是写在docString
.
#string, list, list --> Dictionary
def addMovie (title, charList, actList):
"""The function addMovie takes a title of the movie, a list of characters,
and a list of actors. (The order of characters and actors match one
another). The function addMovie adds a pair to myIMDb. The key is the title
of the movie while the value is a dictionary that matches characters to
actors"""
dict2 = {}
for i in range (0, len(charList)):
dict2 [charList[i]] = actList[i]
myDict = {title, dict2}
return myDict
字典myIMBd
当前为空。但我需要帮助的是循环。当我尝试在跑步者中做到这一点时。
addMovie("Shutter Island", ['Teddy Daniels','Crazy Lady'],['Leodnardo diCaprio', 'old actress'] )
我收到一条错误消息
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
addMovie("Shutter Island", ['Teddy Daniels','Crazy Lady'],['Leodnardo diCaprio', 'old actress'] )
File "C:\Python33\makeDictionary.py", line 10, in addMovie
myDict = {title, dict2}
TypeError: unhashable type: 'dict'
这是否意味着我不能在字典中拥有字典?如果是这样,我如何将它从字典更改为非字典。如果我可以在字典中有一个字典,为什么这不起作用。