I have a list of people and who controls who but I need to combine them all and form several sentences to compute which person control a list of people.
The employee order comes from a txt
file:
I have a list of people and who controls who but I need to combine them all and form several sentences to compute which person control a list of people.
The employee order comes from a txt
file:
from collections import defaultdictcontrols = defaultdict(list)with open('data.txt') as file:for line in file:controller, controlled = line.strip().split(' controls ')controls[controller].append(controlled)print 'employee order:'
for controller, controlled in controls.iteritems(): if len(controlled) > 1:conjoined = ', '.join(controlled[:-1])conjoined = '{} and {}'.format(conjoined, controlled[-1])else:conjoined = controlled[0]print '{} controls {}'.format(controller, conjoined)