[Question]
  [
As you may very well know python has lists. As you might not know these lists can contain themselves.
```
a = []
a.append(a)
```
[Python 2](https://tio.run/nexus/python2#@5@oYKsQHcuVqJdYUJCal6KRqPm/oCgzr0Qh8T8A "Python 2 – TIO Nexus")
[Python 3](https://tio.run/nexus/python3#@5@oYKsQHcuVqJdYUJCal6KRqPm/oCgzrwTEAAA "Python 3 – TIO Nexus")
These are cool and there are lots of interesting things you can do with them, however you cannot compare them.
```
a = []
a.append(a)
b = []
b.append(b)
a == b
```
[Python 2](https://tio.run/nexus/python2#@5@oYKsQHcuVqJdYUJCal6KRqMmVBBFKggklaXIl2tom/f8PAA "Python 2 – TIO Nexus")
[Python 3](https://tio.run/nexus/python3#@5@oYKsQHcuVqJdYUJCal6KRqMmVBBFKggklaXIl2tom/f8PAA "Python 3 – TIO Nexus")
## Task
Your job is to write a function in Python (or any language that can handle python objects directly) that will take two lists that may contain themselves and compare them.
Two lists are equal if they are the same length and there does not exist sequence of numbers such that indexing both of the lists by that sequence results in two objects that are not equal under this definition of equal. All non-list objects contained in a list will be python integers for simplicity and should be compared with python's builtin equality for integers.
Your program *should not* rely on the recursion depth of python to determine if a list is infinitely deep. That is:
```
def isInfinite(a,b):
 try:
  a==b
  return False
 except RunTimeError:
  return True
```
Is not a valid way of determining if two lists are self referential.
## Testcases
Assumes you define a function `equal`
```
a = []
a.append(a)
b = []
b.append(b)
print(equal(a,b))
```
---
```
True
```
---
```
a = []
b = []
a.append(b)
b.append(a)
print(equal(a,b))
```
---
```
True
```
---
```
a = []
b = []
a.append(1)
a.append(b)
b.append(1)
b.append(a)
print(equal(a,b))
```
---
```
True
```
---
```
a = []
a.append(a)
b = [a]
print(equal(a,b))
```
---
```
True
```
---
```
a = []
b = []
c = []
a.append(b)
b.append(c)
c.append(a)
equal(a,b)
```
---
```
True
```
---
```
a=[1,[2]]
b=[1,[2,[1]]]
a[1].append(a)
b[1][1].append(b[1])
```
---
```
True
```
---
```
a = []
a.append(a)
b = [1]
b.append(a)
c = [1]
c.append([c])
print(equal(b,c))
```
---
```
False
```
---
```
a = []
b = []
a.append(1)
a.append(b)
b.append(a)
b.append(1)
print(equal(a,b))
```
---
```
False
```
---
```
a = []
b = []
a.append(a)
b.append(b)
b.append(b)
print f(a,b)
```
---
```
False
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 94 bytes
```
g=lambda c,*p:lambda a,b:c in p or all(map(g((id(a),id(b)),c,*p),a,b))if a>[]<b else a==b
g(0)
```
[Try it online!](https://tio.run/##lVIxUsMwEOz1Ck0qCS4MsrskouQFdJor7hQ7eMZxREgKXm9kRzY2AYY0lvbGu7rb2/Bxej00WdvubE173pL0cBdW6U7AKy@rRgZ5OEqqa7WnoHZKVVtFGuKXtYaOoSH@q3VVSnpyuGFZ1O@FJGtZlHanHnVbvJ2ptqUQ4Vg1J1mqHHI9AofgUAtB0kqHgh4ohKLpXhF8KfFQ4sRSvaLq3xUvx3MxkPmbRiTwRO82stE/C5lbRK/GIfxfG/6PUbwWfqL7pZSErDPgMoxalxs4gxFRPKbtRDipdDAJpN0slsvlQvy@GYMzI3yqja05j3N7GHwc9pliQG41neYLuLYwqVqHa7q3jsDgmjvEETFkuB4C1xs1ps9gZ9UsjpNw5n02B2QgmzKh40bT2k8 "Python 2 – Try It Online")
An improvement on [isaacg's very clever solution](https://codegolf.stackexchange.com/a/117153/20260) of storing the `id` pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.
The recursive step `all(map(...,a,b))` says that `a` and `b` are equal if all corresponding pair of elements in them are equal. This works nicely to reject unequal-length because `map` pads the shortest list with `None`, unlike `zip` which truncates. Since none of the actual lists contain `None`, these padded lists will always be rejected.
[Answer]
# Python, ~~233~~ ~~218~~ ~~197~~ 217 bytes
```
d=id
def q(a,b,w):
 w[(d(a),d(b))]=0
 if d(a)==d(b):return 1
 if(a>[]and[]<b)-1:return a==b
 if len(a)!=len(b):return 0
 for x,y in zip(a,b):
  if((d(x),d(y))in w or q(x,y,w))-1:return 0
 return 1
lambda a,b:q(a,b,{})
```
The anonymous function on the last line performs the desired function.
This is still in the process of being golfed, I just wanted to show that this is possible.
Essentially, we put an entry in w if we're working on a given check. Two things are equal if they're the same object, if they're not lists, and they're equal, or if all their elements are either equal or being worked on. 
]