+ 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

6th Jul 2019, 7:48 AM
Tibor Santa
Tibor Santa - avatar
7 Respostas
+ 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
6th Jul 2019, 4:19 PM
Tibor Santa
Tibor Santa - avatar
+ 11
Well I did some experiments and found this 👇👇 https://code.sololearn.com/cMn85mBPGcqb/?ref=app Thanks
6th Jul 2019, 2:07 PM
Prince PS[Not_Active]
Prince PS[Not_Active] - avatar
+ 9
Tibor Santa yeah bro Ellipsis ... Well happy to help u and thanks for questioning 👍👍
6th Jul 2019, 3:52 PM
Prince PS[Not_Active]
Prince PS[Not_Active] - avatar
+ 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.
6th Jul 2019, 11:46 AM
Schindlabua
Schindlabua - avatar
+ 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)
6th Jul 2019, 3:23 PM
Tibor Santa
Tibor Santa - avatar
+ 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
31st Aug 2019, 1:43 PM
mihai
mihai - avatar
+ 2
I am new
7th Jul 2019, 11:11 AM
Antu Sharma
Antu Sharma - avatar