Self-referencing list | Sololearn: Learn to code for FREE!


Self-referencing list

I came across this in one of the challenge questions. When we append a list to itself in Python, we can achieve an unlimited chain of references. It behaves sort of like a sym-link pointing to itself. We can look into any depth of the 'recursed' list and find the same list again. My question: anyone have experience or any ideas of a real problem or use-case where this concept could be utilized?

7/6/2019 7:48:50 AM

Tibor Santa

7 Answers

New Answer


I did some more thinking, and I figured out a scenario where this self-reference could be useful. Remember those really old RPG games where you move about in a dungeon, and sometimes you might get into a dead end from where there is no escape? I made a small sample code to show this concept, I hope it makes sense!


Well I did some experiments and found this 👇👇 Thanks


Tibor Santa yeah bro Ellipsis ... Well happy to help u and thanks for questioning 👍👍


That's pretty funny. It reminds me of the useless function: function lol() { return lol; } lol()()()()()()()()()()()()(); I cannot think of any usecases where you do it on purpose. Only maybe accidentally: You are writing a programming language interpreter so you have a stack that keeps track of variables. Maybe that programming language allows you to manipulate the stack, so you can have a variable on the stack that is a reference to the stack itself. Though circular data structures are not uncommon. In the DOM, everything points to each other a whole bunch. But that's not quite the same is it.


Prince PS [#Not_Active......] that was pretty awesome. I did not even dare trying to print the list... And it turns out, Python is actually smart enough to recognise a circular reference like this, and print it as an Ellipsis: [[...]] (normally python would have no problem with printing deeply nested data structures)


I recently make a tic tac toe play algorithm and solve a very tricky problem basically assigning a list as arguments to a recursive function. If you are interested to see the tic tac toe algorithm please check it out :)


I am new