Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement simple Tree representation of default Dictionary by python

Shulou Source: shulou.com Published: 2022-06-01 05:43:00 10月05日 Update

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!

Tags: Dictionaries content articles value interests guys buddies more knowledge industry information channels channels references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MySQL MariaDB OPPO Reno Shulou Technology