How to implement simple Tree representation of default Dictionary by python
This article mainly introduces python how to achieve the simple tree expression of the default dictionary, the article is very detailed, has a certain reference value, interested friends must read it!
A simple tree representation of the default dictionary
> > import json > tree = lambda: collections.defaultdict (tree) > root = tree () > root ['menu'] [' id'] = 'file' > root [' menu'] ['value'] =' File' > root ['menu'] [' menuitems'] ['new'] [' value'] = 'New' > > root [' menu'] ['menuitems'] [' new'] ['onclick'] =' new () Root ['menu'] [' open'] ['value'] =' Open' > root ['menu'] [' menuitems'] ['open'] [' onclick'] = 'open ();' > > root ['menu'] [' menuitems'] ['close'] [' value'] = 'Close' > root [' menu'] ['menuitems'] [' close'] ['onclick'] =' close () Print json.dumps (root, sort_keys=True, indent=4, separators= (',',':)) {"menu": {"id": "file", "menuitems": {"close": {"onclick": "close () , "value": "Close"}, "new": {"onclick": "new ();", "value": "New"}, "open": {"onclick": "open () "," value ":" Open "}}," value ":" File "} above are all the contents of the article" how to implement the simple tree representation of the default dictionary in python ". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!