# Python Recursive comment Tree Chart code

Source: Internet
Author: User

First I need to record this code, because I have encountered this problem, and then did not solve

Later, the previous paragraph said I found a piece of code for me to see, I did not care, and then she realized that she realized, she really realized, I ...

In order to thank her, I played with her for a noon Gobang, and pretended to lose a few

First, the purpose:

Recursive iterations

Look at the data again:

In fact, there is a premise that aid cannot be repeated

FID is the parent ID, which points to the aid

If aid = = FID, the aid that proves FID is a subset

If FID = = 0 proves to be the top

Code:

`def aaa (Oldarr, FID): NEWARR= []     forIinchOldarr:ifi["FID"] ==Fid:obj= {"Aid": i["Aid"],"Description": i["Description"]} Child= AAA (Oldarr, i["Aid"])            ifLen (Child) >0: obj[" Child"] =Child newarr.append (obj)returnNEWARRif__name__ = ='__main__': Li= [        {"Aid":5,"FID":1,"Description":"Career Values 4","vid":1,"VariableName":"Standard coefficient"},        {"Aid":1,"FID":3,"Description":"Career Values 1","vid":1},        {"Aid":4,"FID":3,"Description":"Career Values 2","vid":2},        {"Aid":7,"FID":3,"Description":"Career Values 3","vid":3},        {"Aid":2,"FID":0,"Description":"Education","vid":4},        {"Aid":3,"FID":0,"Description":"Time","vid":5},] res= {"dirname":"","Child_dirs": [],"Files": []} print (AAA (LI,0))`

Python Recursive comment Tree Chart code

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.