为啥要写,因为用到了,不看不行了,那就看看呗
看了17分钟,给我的感觉就是 判断逻辑正常走,然后return自己
我的目标呢就是获取最儿子层的id,所以这么写,,
代码如下
# -*- coding: utf-8 -*-
# @create_time : 2022/7/14 下午8:55
# @Author : CY
# @File : xxx.py
a = [
{
"id": "1547510177782173696",
"parentId": "0",
"weight": 1,
"name": "区域名称",
"children": [
{
"id": "1547511157533839360",
"parentId": "1547510177782173696",
"weight": 2,
"name": "11",
"children": [
{
"id": "1547511182317981696",
"parentId": "1547511157533839360",
"weight": 3,
"name": "11-11",
"children": [
{
"id": "1547511210352709632",
"parentId": "1547511182317981696",
"weight": 4,
"name": "11-11-22",
"children": [
{
"id": "1547511264534728704",
"parentId": "1547511210352709632",
"weight": 5,
"name": "11-11-22-11"
}
]
}
]
}
]
}
]
}
]
def get_children_data(list_data):
ch_data = list_data[0].get('children', None)
if ch_data is None: return list_data[0].get('id')
return get_children_data(ch_data)
if __name__ == '__main__':
cc = get_children_data(a)
print(cc)