I am looking for levels of separation between any two stars inside a movie database. I succeed after i achieve my base situation, that is 1 amount of separation (i.e. actor is within same movie as the second actor) however i use recursion to locate other levels of separation, and that i get:

runtime error: maximum recursion depth exceeded in cmp.
##gets file with movie information
f = open("filename.txt")
actedWith = {}
ActorList = []
movies = {}
actedIn = []
dos = 1

def getDegrees(target, base, dos):
    for actor in actedWith[base]:
        if target == actor:
            print base, "has ", dos, " degree(s) of separation from ", target
            return
    dos = dos+1
    for actor in actedWith[base]:
        getDegrees(target, actor, dos)


for l in f:
    ##strip of whitespace
    l = l.strip()
    ##split by where forward-slashes are
    l = l.split("/")
    ##add the first "word" on the line to the database of movie names
    movies = {l[0] : l[1:]}
    for e in l[1:]:
        if e in actedWith:
            actedWith[e] = actedWith[e]+movies[l[0]]
        else:
            actedWith[e] = movies[l[0]]

base = raw_input("Enter Actor Name (Last, First): ")
target = raw_input("Enter Second Actor Name (Last, First): ")
getDegrees(target, base, dos)

Text file I personally use are available at http://www.mediafire.com/?qtryvkzmuv5jey3

To check base situation, I personally use: Bacon, Kevin and Pitt, Brad.

To check others I personally use Bacon, Kevin and Gamble, Nathan.

Two suggestions (I've not looked around the text file, just happening first concepts here along with a quick read of the code):

  1. Whenever you return from getDegrees, you are still studying the relaxation from the function following a return. You have to return a genuine (or something like that) to point the search has ended and also the entire function call stack ought to be folded back. The very first return would switch to "return True" and also the last line would switch to "if getDegrees(target, actor, dos): return True".
  2. Keep an eye on which stars happen to be looked. If two stars have each behaved with one another, or there's a cycle within the associations, you'll loop backwards and forwards.

This code tries to fix both return and graph cycle problems. However, there's still a logic error somewhere Kevin Sausage and James Belushi (amount of separation of two) provide the following:

Siravo, Frederick has 179 degree(s) of separation from Belushi, James

Edit: fixed with the addition of the "original" parameter.

however the recursion issue is fixed.

##gets file with movie information
f = open("filename.txt")
actedWith = {}
ActorList = []
movies = {}
actedIn = []
dos = 1

def getDegrees(original, target, base, dos=0, seen=[]):
    dos = dos+1
    print "----> checking %s against %s" % (target, base)
    for actor in actedWith[base]:
        #print "\t" + actor
        if target == actor:
            print original, "has ", dos, " degree(s) of separation from ", target
            return True
    for actor in actedWith[base]:
        if actor in seen: continue
        seen = seen + [actor]
        if getDegrees(original, target, actor, dos, seen):
            return True
    return False


for l in f:
    ##strip of whitespace
    l = l.strip()
    ##split by where forward-slashes are
    l = l.split("/")
    ##add the first "word" on the line to the database of movie names
    movies = {l[0] : l[1:]}
    for e in l[1:]:
        if e in actedWith:
            actedWith[e] = actedWith[e]+movies[l[0]]
        else:
            actedWith[e] = movies[l[0]]

original = raw_input("Enter Actor Name (Last, First): ")
target = raw_input("Enter Second Actor Name (Last, First): ")
getDegrees(original, target, original)

Example:

Bacon, Kevin has  65  degree(s) of separation from  Kosaka, Masami

Unless of course there's some property of actedWith I am not seeing, you've got nothing in position to avoid an infinite loop. For instance, your recursive calls is going to be getDegrees("Gamble, Nathan", "Pitt, Brad", 2), then since Kevin Sausage has behaved with Kaira Pitt, when you are another level much deeper you'll call getDegrees("Gamble, Nathan", "Bacon, Kevin", 3). Begin to see the problem?