Code:

data = [[1,5,8],[3,6],[],[3],[],[],[],[],[17],[], \
[4],[22,23,24],[],[],[],[4],[],[20],[],[5], \
[8],[29],[],[],[12],[],[5],[],[4,22],[27]]
visited = [0]*len(data)
def main():
for i in range(len(data)):
if not visited[i]:
recurse(i, [i], [0]*i+[1]+[0]*(len(data)-i-1))
def recurse(node, parents, marked):
visited[node] = 1
for i in data[node]:
# check for membership chain
if marked[i]:
printerr(i, parents)
# recurse
if not visited[i]:
recurse(i, parents+[i], marked[0:i]+[1]+marked[i+1:len(data)])
def printerr(node, L):
s = str(node)
i = len(L)-1
while L[i] != node:
s += " is in " + str(L[i])
i -= 1
print s + " is in " + str(node)
main()

I'm understanding better how the stack implementation works; this thread continues to be very educational.