from collections import defaultdict import json def tree(): return defaultdict(tree) categories = tree() a = categories[‘Programming Languages‘][‘Python‘] b = categories[‘Programming Languages‘][‘java‘] a[‘Standard Library‘][‘sys‘]=‘sys‘ a[‘Standard Library‘][‘os‘]=‘os‘ b[‘Standard Library‘][‘os‘]=‘jos‘ print(json.dumps(categories)) 输出: {"Programming Languages": {"Python": {"Standard Library": {"sys": "sys", "os": "os"}}, "java": {"Standard Library": {"os": "jos"}}}}
时间: 2024-10-09 20:51:19