Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. class Actor:    
  2.     def __init__(self):
  3.         self.movies = []
  4.     def addMovie(self, x):#neighbor
  5.         self.movies.append(x)
  6.  
  7. class Movie:
  8.     def __init__(self):
  9.         self.actors = []
  10.     def addActor(self, x):#neighbor
  11.         self.actors.append(x)
  12.  
  13. def sixDegrees(actor, endactor):
  14.     return parseFile(getName())
  15.     #return search(actor, endactor, 0, [])
  16.            
  17. def getName():
  18.     filename = input("Enter the name of the input file including file extension: ")
  19.     return filename
  20.  
  21. def parseFile(filename):
  22.     file = open(filename)
  23.     lst=[]
  24.     for line in file:
  25.         lst.append(line.split())
  26.     for x in lst:#Movie Class
  27.         movie = x[0]
  28.         movie = Movie()#creates new movies
  29.         for a in range(1,len(lst), 2):
  30.             fullname = str(lst[a]) + " "+ str(lst[a+1])
  31.             movie.addActor(fullname)#adds actors to movie
  32.             fullname = Actor()#creates new actors
  33.             fullname.addMovie(movie)#adds movie to actors
  34.    
  35. def search(actor, endactor, count, visited):
  36.     for movie in actor.movies:
  37.         if movie not in visited and count <= 3:
  38.             visited.append(movie)
  39.             for actor in movie.actors:
  40.                 if actor in movie.actors:
  41.                     if actor == endactor:
  42.                         return [actor,movie]
  43.                     else:
  44.                         return [actor,movie] + search(actor,endactor, count+1, visited)
  45.    
  46. print(sixDegrees('John Cusack', 'Kevin Bacon'))
  47. for l in Actor:
  48.     print(l)
  49. #TypeError: 'Actor' object is not iterable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement