How to pretty-print cyclic dictionaries?

D

Dietrich Bollmann

Hi,

I would like to represent graphs as cyclic dictionaries in Python.

The python code for the graphs is generated by some other program
(written in lisp) and I wonder what would be the best syntax for writing
the cycles in Python?

The following works:

As can be seen here:
a {'a': {...}}
a['a'] {'a': {...}}
a['a']['a'] {'a': {...}}
a['a']['a']['a'] {'a': {...}}

but I wonder if there is some easier syntax to represent the cycles?

"Tags" like the following would be ideal:

[0] {'a': [0]}

but is there something like this in Python?

Thanks, Dietrich


PS: If there is such a representation, how could I make Python print it
out?

The normal printing is not very informative:
{'a': {...}}

And Pythons pretty-print functionality is not better either:
{'a': <Recursion on dict with id=3076782660>}

Any idea?

Thanks again :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top