w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python: Function that searches through a dictionary in a dictionary

You need to populate your myIMDB dictionary in findActor before you use it.

In addition, I'd suggest mapping myIMDB directly from the title of the move to characters. In other words, instead of doing myIMDb[len(myIMDb)] = {title: dict2} in your addMoive, you should just do myIMDb[title] = dict2.

This way, when you need to look up the title and character, you can simply do:

def findActor(title, name):
    if title in myIMDb:
        if name in myIMDb[title]:
            return myIMDb[title][name]
    return "Error: No movie found"




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.