python - Convert tree to list of lists -


I have a tree structure, something like: company -> department -> roles ->

I have a triple for loop-structure like this:

  for company in self.Companies (): cName = company.Name () for the department in the company. (): Roles (): rName = role.Name () roleID = role.ID ()  

for the role in the department (dName = department.Name () section. () Function Android-Sales Companies can divide zero or more.

So far I have all the above. I am trying to develop it so that I can find a list of lists. Ideally I want this. If something repeats, the next item in the list should be left blank or it can not have any fields, in that case also leave it empty.

[
['Google' , 'Android-Sales', 'Marketer', 'A123'],
[',' Google-Play ',' Developer ',' A435 '],
[' ',' ',' Examiner ',' A 125 '],
[' ',' ',' ',' A126 '],
[' My small company ',' ',' Super roll ',' A 123 '] ]

or it will also work ...

[
['Google', 'Android-Sales',' Marketer ',' A123 '], [[' Google ',' Google-Play ',' Developer ',' A435 '],
[' Google '[' Google-Play ',' Tester ',' A125 '],
['Google', 'Google-Play', 'Tester', 'A126'],
['My Small Company', ' ',' Super Roll ',' A 123 '] (There is no one in "My Small Company"> Department).

Each internal list length must be of 4.

  tree = {"Google": {"Android": " 

output:

['Google', 'Nexus', 'No'], ['Google', 'Android', 'Yes']]

Comments