Given a list of employees and their bosses as a csv file , write a function that will print out a hierarchy tree of the employees.
Sample input from csv file
Sam, Ian, technical lead, 2009 / Ian, NULL, CEO,2007/ Fred, Sam,developer, 2010
The format is name, supervisor, designation, year of joining.
The output should be
Ian CEO 2007
-Sam Technical lead 2009
--Fred Developer 2010
I am not sure but I have tried it as below. Please suggest changes to this code or any other solutions you have.
strq = "Sam, Ian, technical lead, 2009 / Ian, NULL, CEO,2007/Fred, Sam, developer, 2010"
def treeEmployee(infoStr):
str1 = infoStr.split("/")
s2 = []
for i in str1:
s2.append(i.split(","))
for i in range(len(s2)):
for j in range(1, len(s2)):
if s2[i][1] == s2[j][0]:
s2[i], s2[j] = s2[j], s2[i]
return s2
print treeEmployee(strq)
I want the output to be
Ian CEO 2007
-Sam Technical lead 2009
--Fred Developer 2010