Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Actor:
- def __init__(self):
- self.movies = []
- def addMovie(self, x):#neighbor
- self.movies.append(x)
- class Movie:
- def __init__(self):
- self.actors = []
- def addActor(self, x):#neighbor
- self.actors.append(x)
- def sixDegrees(actor, endactor):
- return parseFile(getName())
- #return search(actor, endactor, 0, [])
- def getName():
- filename = input("Enter the name of the input file including file extension: ")
- return filename
- def parseFile(filename):
- file = open(filename)
- lst=[]
- for line in file:
- lst.append(line.split())
- for x in lst:#Movie Class
- movie = x[0]
- movie = Movie()#creates new movies
- for a in range(1,len(lst), 2):
- fullname = str(lst[a]) + " "+ str(lst[a+1])
- movie.addActor(fullname)#adds actors to movie
- fullname = Actor()#creates new actors
- fullname.addMovie(movie)#adds movie to actors
- def search(actor, endactor, count, visited):
- for movie in actor.movies:
- if movie not in visited and count <= 3:
- visited.append(movie)
- for actor in movie.actors:
- if actor in movie.actors:
- if actor == endactor:
- return [actor,movie]
- else:
- return [actor,movie] + search(actor,endactor, count+1, visited)
- print(sixDegrees('John Cusack', 'Kevin Bacon'))
- for l in Actor:
- print(l)
- #TypeError: 'Actor' object is not iterable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement