我有一个由列表组成的树,类似于具有目录和文件递归列表的顶级目录。我想将其可视化为打印的树。
如何查看打印为树的列表列表?
数据
tree = [
['Main University'],
['Main University', 'Academic Affairs'],
['Main University', 'Academic Affairs', 'College of Health Sciences'],
['Main University', 'Academic Affairs', 'College of Arts & Science'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Biology'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Chemistry/Physics'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Chemistry/Physics', 'Physics'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Biology', 'Biochemistry & Molecular Bio'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Biology', 'Earth Sciences'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Biology', 'Environmental Studies'],
['Main University', 'Academic Affairs', 'College of Health Sciences', 'Social Work'],
['Main University', 'Academic Affairs', 'College of Arts & Science', 'Chemistry/Physics', 'Chemistry'],
['Main University', 'Academic Affairs', 'College of Health Sciences', 'Health Sciences'],
['Main University', 'Academic Affairs', 'College of Health Sciences', 'Occupational Therapy']
]
所需输出(或类似;即,像¦--
、°--
等字形无关紧要)
Main University
°--Academic Affairs
¦--College of Arts & Science
¦ ¦--Chemistry/Physics
¦ ¦ ¦--Physics
¦ ¦ °--Chemistry
¦ °--Biology
¦ ¦--Biochemistry & Molecular Bio
¦ ¦--Earth Sciences
¦ °--Environmental Studies
°--College of Health Sciences
¦--Health Sciences
¦--Occupational Therapy
°--Social Work
2条答案
按热度按时间sg3maiej1#
如果数组不是太大,你可以先把它转换成树,然后打印出来
输出以下内容
kmpatx3s2#
bigtree package可以很好地做到这一点:
收益率: