Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
#Creates graph
def loadGraphFile(file):
    graph = []
    for line in file:
        contents = line.split()
        movieName = contents[0]
        actorNames = [contents[i]+ " " + contents[i+1] for i in range(1, len(contents), 2)]        
        movieNode = findNode(graph, movieName)
        if movieNode == None:
            movieNode = mkNode(movieName)
            graph.append(movieNode)
        for actorName in actorNames:            
            actorNode = findNode(graph,actorName)
        if actorNode == None:
            actorNode = mkNode(actorName)
            graph.append(actorNode)
        actorNode.neighbor.append(movieNode)
        movieNode.neighbor.append(actorNode)
        return graph
        
def loadGraphFileName(file = 'file.txt'):
    return loadGraphFile(open(file))
Posted
Updated 27-Nov-14 10:05am
v2
Comments
Richard MacCutchan 28-Nov-14 3:53am    
What error, which line of code, what is supposed to happen?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900