+ 17
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? https://code.sololearn.com/cS3eUo5MtvtH/?ref=app
7 Answers
+ 8
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!
https://code.sololearn.com/c47Uq02cP4Fu/?ref=app
+ 11
Well I did some experiments and found this đđ
https://code.sololearn.com/cMn85mBPGcqb/?ref=app
Thanks
+ 9
Tibor Santa yeah bro Ellipsis ...
Well happy to help u and thanks for questioning đđ
+ 5
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.
+ 5
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)
+ 4
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 :)
https://code.sololearn.com/cpTxVxeTZS5Z/?ref=app
+ 2
I am new