RuntimeError: maximum recursion depth exceeded in cmp

2012-02-16 Thread OwenLJN
Hi
I wrote a python function self_contained(x) that finds all lists in x that
contain themselves.
Here's the body of the function:

def self_contained(x):
L = []
if not isinstance(x, list):
return []
for i in x:
if isinstance(i, list):
if i in i:
L += [i]
return L

L5 =[]
L6 = []
L5.append(L6)
L6.append(L5)

then I compare L5 and L6 in shell:
L5 == L6
and it gives me this error:
RuntimeError: maximum recursion depth exceeded in cmp
I think probably I need to add another parameter to self_contained or to a
helper function to make my function work when I call L5 or L6. So How can I
fix this error??
I put this code: sys.setrecursionlimit(2500) in the begining doens't fix the
error.
And I don't know how to change self_contained to a recursive function can
any1 help me with this?Thanks!


--
View this message in context: 
http://python.6.n6.nabble.com/RuntimeError-maximum-recursion-depth-exceeded-in-cmp-tp4471100p4471100.html
Sent from the Python - python-bugs-list mailing list archive at Nabble.com.
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: RuntimeError: maximum recursion depth exceeded in cmp

2012-02-16 Thread OwenLJN
Let me restate my question:I want to make self_contained(L5) and
self_contained(L6) work, but I get RuntimeError how can I fix this by adding
one more parameter to check if a list inside a list was seen before, and
then stop the loop to prevent the error message from showing again? And I
found that the id of L5 is different with L6 and
"L5 in L6" and "L6 in L5" returns True

--
View this message in context: 
http://python.6.n6.nabble.com/RuntimeError-maximum-recursion-depth-exceeded-in-cmp-tp4471100p4474728.html
Sent from the Python - python-bugs-list mailing list archive at Nabble.com.
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com