![]() |
Representation of recursive list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Bar (https://python-forum.io/forum-27.html) +--- Thread: Representation of recursive list (/thread-13029.html) |
Representation of recursive list - DeaD_EyE - Sep-24-2018 Guess you have following code: x = [1, 2, 3] x.append(x) print(x)The output: Did you know/expect that? It's infinite, because it refers on itself. You can do this: RE: Representation of recursive list - snippsat - Sep-24-2018 Cool not seen that before. pprint gives some more info. λ ptpython >>> from pprint import pprint >>> x = [1, 2, 3] >>> x.append(x) >>> x [1, 2, 3, [...]] >>> pprint(x) [1, 2, 3, <Recursion on list with id=88766544>] >>> x[-1] [1, 2, 3, [...]] >>> x == x[-1] True |