The following simple comparison of pure lists explodes on me:
a, b = [], []
for _ in range(1000):
a, b = [a], [b]
a == b
Python 3.5.1:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
a == b
RecursionError: maximum recursion depth exceeded in comparison
Python 2.7.11:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
a == b
RuntimeError: maximum recursion depth exceeded in cmp
Does the language/library offer a safe way to compare such deeply nested lists, or will I have to write my own iterative comparison code?
Edit: I'm asked to explain why my question isn't a duplicate of this. It isn't because that one is about infinite nesting and because I'm not asking for an explanation (I understand it already) but for whether Python offers a simple solution.