list_of_lists = [['PARENT', 'ID', 'DESCRIPTION1', 'DESCRIPTION2'],
['', 'R1', 'R1_Des_1', '0'],
['C1', 'E1', 'E1_Des_1', '1'],
['P1', 'C1', 'C1_Des_1', '2'],
['R1', 'P1', 'P1_Des_1', '3'],
['C2', 'E2', 'E2_Des_1', '4'],
['P2', 'C2', 'C2_Des_1', '5'],
['R1', 'P2', 'P2_Des_1', '6'],
['P2', 'C3', 'C3_Des_1', '7'],
['C4', 'E3', 'E3_Des_1', '8'],
['P3', 'C4', 'C4_Des_1', '9'],
['R2', 'P3', 'P3_Des_1', '10'],
['None', 'R3', 'R3_Des_', '11'],
['P3', 'C5', 'C5_Des_1', '12'],
['C6', 'E4', 'E4_Des_1', '13'],
['P4', 'C6', 'C6_Des_1', '14'],
['R2', 'P4', 'P4_Des_1', '15'],
['C7', 'E5', 'E5_Des_1', '16'],
['P5', 'C7', 'C7_Des_1', '17'],
['R3', 'P5', 'P5_Des_1', '18'],
['C9', 'E6', 'E6_Des_1', '19'],
['P6', 'C9', 'C9_Des_1', '20'],
['R3', 'P6', 'P6_Des_1', '21'],
['P6', 'C8', 'C8_Des_1', '22'],
['C10', 'E7', 'E7_Des_1', '23'],
['P7', 'C10', 'C10_Des_1', '24'],
['R4', 'P7', 'P7_Des_1', '25'],
['P7', 'C11', 'C11_Des_1', '26'],
['C12', 'E8', 'E8_Des_1', '27'],
['P8', 'C12', 'C12_Des_1', '28'],
['R4', 'P8','','29'],
['', 'P8','','30'],
['R1', 'P8','','31'],
['', 'z1','','32'],
['z1', 'z2','','33'],
['z1', 'z3','','34'],
['z2', 'z4','','35'],
['z3', 'z4','','36']]
list_of_lists_slice = list(list_of_lists)
list_string = []
for sublist in list_of_lists_slice:
for element in sublist:
if len(element) > 8:
element = element[:7]
if len(element) < 8:
space = 8 - len(element)
element = element + (' ' * space)
for sublist in list_of_lists_slice:
row_str = str(' |')
ele_str = '|'.join(sublist)
row_str = row_str + ele_str + ('| ')
list_string.append(row_str)
middle = (' ')
middle = middle + str((len(sublist)) * (9 * ('-')))
list_string.append(middle)
for row in list_string:
print (row)