Click here to Skip to main content
15,895,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 = 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

What I have tried:

Python
import csv
with open("list.csv", 'r') as csv_file:
list_reader = csv.reader(csv_file, delimiter=",")
employee_list = {
    name: boss.strip() for name, boss, designation, year in list_reader}
mgrs = [k for k, v in employee_list.items() if v == '']
while mgrs:
    print ", ".join(mgrs)
    mgrs = [k for k, v in employee_list.items() if v in mgrs]


name: boss.strip() for name, boss, designation, year in list_reader}
ValueError: too many values to unpack
Posted
Updated 11-Jul-16 7:40am
v3

I cannot quite figure out what that code is supposed to do. however I think you should be using string.split[^], not string.strip[^].
 
Share this answer
 
C#
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


Can we do it this way?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900