Goal: create a self-referencing tuple satisfying
x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only.
Answers meeting this extra condition are prioritised (which may be impossible): this tuple should also be insertable into a dict or set.
If the extra condition is impossible, apart from the low-hanging optimization of the below code, I am still interested in a qualitatively different approach of similar length or better.
I had previously assumed this answer to be one of the shortest, but as @mousetail brought up, actually it crashes python when inserted into a dict or set.
import ctypes tup = (0,) ctypes.c_longlong.from_address(id(tup)+24).value = id(tup)
I notice this also happens with the other answer in that post, so I'm wondering if there's a way to resolve it (the ideal answer), or if that is inherent in python.