これがこれまでの私のプログラムです。私がする必要があることは に書かれてい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'
それは、辞書の中に辞書を入れることができないということですか? もしそうなら、どうすればそれを辞書から非辞書に変更できますか。dict 内に dict を持つことができる場合、なぜこれが機能しないのですか。