Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- def fillActors(actor):
- movies={}
- f1=open("C:/Users/Ante/Desktop/movies.txt","r");
- line=f1.readline()
- while(line!=""):
- getMovie(movies,line)
- line = f1.readline()
- bfs(movies,actor)
- def getMovie(movies,line):
- isMovie= True
- actors=[]
- end = len(line)
- while True:
- start = line.find(";")
- if(start!= -1):
- if(isMovie):
- movieName=line[0:start]
- line=line[start+1:end]
- isMovie=False
- else:
- glumac=line[0:start]
- actors.append(glumac)
- line=line[start+1:end]
- else:
- actors.append(line.strip("\n"))
- break;
- movies[movieName]=actors
- def findActors(actor,movies):
- connected=[]
- for key,value in movies:
- if(actor in value):
- for i in value:
- if(i == actor):
- continue
- else:
- connected.append(i)
- else:
- continue
- def bfs(movies,actor):
- visited = []
- S = str(actor)
- T=str("Kevin Bacon")
- q = [[actor]]
- if S == T:
- return visited
- while q:
- path = q.pop(0)
- top = path[-1]
- if top not in visited:
- connected_actors = findActors(top,movies)
- for find in connected_actors:
- otherpath = list(path)
- otherpath.append(find)
- q.append(otherpath)
- if find == T:
- return otherpath
- visited.append(top)
- return -1
- fillActors("Steve Martin")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement