aa = [
{'ip': '192.168.1.1', 'projectname__pname': 'hh', 'id': 1, 'projectname_id': 1},
{'ip': '192.168.3.2', 'projectname__pname': 'hh', 'id': 2, 'projectname_id': 1},
{'ip': '192.168.22.3', 'projectname__pname': 'qm', 'id': 3, 'projectname_id': 2},
{'ip': '192.168.5.3', 'projectname__pname': 'ssh', 'id':4, 'projectname_id': 3}
]
大家好,我想把aa中的列表生成以下bb的格式,请问代码怎么实现
bb = [
{'projectname_id': 1, 'projectname__pname': 'hh', 'children': [{'id': 1, 'text': '192.168.1.1'},{'id': 2, 'text': '192.168.1.2'}]},
{'projectname_id': 2, 'projectname__pname': 'qm', 'children': [{'id': 3, 'text':'192.168.22.3'}]},
{'projectname_id': 3, 'projectname__pname': 'ssh', 'children': [{'id': 4, 'text': '192.168.5.3'}]}
]