Pythons objects can be recursive
·
Sai Kiran
Python objects can be recursive! for example, to a list you can add itself as an element.
a = [1,2,3]
a.append(a)
print(a)
Python’s copy module highlights this problem.
We can use id()
to get unique identifier for each object and traverse all its contained objects and mark if we have visited them already or not.