Explain in detail what the following code is doing:     import sys """ This functions build the title-actors dictionary.  The keys are movie titles, and the values are the cast lists of each movie.""" def make_title_dict():         titleActorDict = {} # create an empty dict (movie title -> key, list of actor(s) )         with open("imdb.txt", "r") as fHandle: # open file for reading         lines = fHandle.readlines() # list of lines from the input file           for index in range (0, len(lines), 2):         title = lines[index].strip().lower() # movie name -> key         actor = lines[index+1].strip().lower() # actor name -> value                if title in titleActorDict:  # already in Dict             titleActorDict[title].append(actor)              else :  # its not in the Dict yet              titleActorDict[title] = [actor] # list of actors, add that one actor to begin with       return titleActorDict """ Define the following functions to return the requested result """ def getNumFilms(titleActorDict):     res = list(titleActorDict.keys()) #listing out the data     return len(res) #returning length of list for number of films      def getLongestCastList(titleActorDict):     keys = list(titleActorDict.keys()) #listing out the data     maxCastNum = 0 #setting the maxCastNum     for key in keys: #creating a loop to iterate over the list         if(maxCastNum < len(titleActorDict[key])):              maxCastNum = len(titleActorDict[key])      return maxCastNum #returning the longest cast list      def getShortestCastList(titleActorDict):      keys = list(titleActorDict.keys())     minCastNum = 9999999 #setting the minCastNum     for key in keys:         if (minCastNum > len(titleActorDict[key])):             minCastNum = len(titleActorDict[key]) #doing something similar when getting the Longest cast list     return minCastNum def lookupActor(titleActorDict, movie, actor):     if(actor in titleActorDict[movie]): #checks if actor is within list         return True     else:         return False      def getCommonActors(titleActorDict, movie1, movie2):     resList = []     actor_list1 = titleActorDict[movie1]     actor_list2 = titleActorDict[movie2]     for actor in actor_list1:         if(actor in actor_list2):             resList.append(actor)     return resList      def getCommonActors_v2(titleActorDict, movie1, movie2, movie3):     if movie1 in titleActorDict and movie2 in titleActorDict and movie3 in titleActorDict:         actor_list1 = titleActorDict[movie1]         actor_list2 = titleActorDict[movie2]         actor_list3 = titleActorDict[movie3]         common_actors = list(set(actor_list1) & set(actor_list2) & set(actor_list3))         return common_actors     return [] def getActorMovieList(titleActorDict, actor):     movies = [movie for movie, cast_list in titleActorDict.items() if actor in cast_list]     return movies titleActorDict = make_title_dict()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

Explain in detail what the following code is doing:

 

 

import sys

""" This functions build the title-actors dictionary. 
The keys are movie titles, and the values are the cast lists of each movie."""
def make_title_dict():    
    titleActorDict = {} # create an empty dict (movie title -> key, list of actor(s) )    
    with open("imdb.txt", "r") as fHandle: # open file for reading
        lines = fHandle.readlines() # list of lines from the input file 
    
    for index in range (0, len(lines), 2):
        title = lines[index].strip().lower() # movie name -> key
        actor = lines[index+1].strip().lower() # actor name -> value       
        if title in titleActorDict:  # already in Dict
            titleActorDict[title].append(actor)     
        else :  # its not in the Dict yet 
            titleActorDict[title] = [actor] # list of actors, add that one actor to begin with  
    return titleActorDict

""" Define the following functions to return the requested result """

def getNumFilms(titleActorDict):
    res = list(titleActorDict.keys()) #listing out the data
    return len(res) #returning length of list for number of films
    
def getLongestCastList(titleActorDict):
    keys = list(titleActorDict.keys()) #listing out the data
    maxCastNum = 0 #setting the maxCastNum
    for key in keys: #creating a loop to iterate over the list
        if(maxCastNum < len(titleActorDict[key])): 
            maxCastNum = len(titleActorDict[key]) 
    return maxCastNum #returning the longest cast list
    
def getShortestCastList(titleActorDict): 
    keys = list(titleActorDict.keys())
    minCastNum = 9999999 #setting the minCastNum
    for key in keys:
        if (minCastNum > len(titleActorDict[key])):
            minCastNum = len(titleActorDict[key]) #doing something similar when getting the Longest cast list
    return minCastNum

def lookupActor(titleActorDict, movie, actor):
    if(actor in titleActorDict[movie]): #checks if actor is within list
        return True
    else:
        return False
    
def getCommonActors(titleActorDict, movie1, movie2):
    resList = []
    actor_list1 = titleActorDict[movie1]
    actor_list2 = titleActorDict[movie2]
    for actor in actor_list1:
        if(actor in actor_list2):
            resList.append(actor)
    return resList
    
def getCommonActors_v2(titleActorDict, movie1, movie2, movie3):
    if movie1 in titleActorDict and movie2 in titleActorDict and movie3 in titleActorDict:
        actor_list1 = titleActorDict[movie1]
        actor_list2 = titleActorDict[movie2]
        actor_list3 = titleActorDict[movie3]
        common_actors = list(set(actor_list1) & set(actor_list2) & set(actor_list3))
        return common_actors
    return []
def getActorMovieList(titleActorDict, actor):
    movies = [movie for movie, cast_list in titleActorDict.items() if actor in cast_list]
    return movies
titleActorDict = make_title_dict()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education