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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top