Need to Display mmeName and IP in horizontal, if we find duplicate source and Target, but my code is displaying vertically


#1

i need to format excel data using openpyxl in python: In the result_lists we have some duplicate ids with different IPs, so, for now, I’m getting result as Click here for my output but whenever we find duplicate source and target then we need to display mmeName and Missing IP in horizontal, can you please help me to do this. and get my required output as Required Output

def writing_results(result_lists, result_sheet):
        result_lists = [[('32891', '32822', 'EKRGMD92-vMME-01', '10.88.158.81'), 
                        ('32822', '32781', 'EKRGMD92-vMME-02', '10.88.159.113'), 
                        ('32822', '32781', 'HRSNNJAQ-vMME-01', '10.88.162.81'), 
                        ('32822', '32781', 'HRSNNJAQ-vMME-02', '10.88.163.113'), 
                        ('33033', '32891', 'EKRGMD92-vMME-02', '10.88.159.113'), 
                        ('33033', '32891', 'HRSNNJAQ-vMME-01', '10.88.162.81'), 
                        ('33033', '32891', 'HRSNNJAQ-vMME-02', '10.88.163.113'), 
                        ('33033', '32822', 'EKRGMD92-vMME-01', '10.88.158.81'), 
                        ('33033', '32781', 'EKRGMD92-vMME-02', '10.88.159.113'), 
                        ('33033', '32781', 'HRSNNJAQ-vMME-01', '10.88.162.81'), 
                        ('33033', '32781', 'HRSNNJAQ-vMME-02', '10.88.163.113'), 
                        ('32781', '32891', 'KSCYMOEC-MME-03', '10.148.9.19')],
                        [('32822', '32891', 'HRSNNJAQ-vMME-02', '10.88.163.113'), 
                        ('32781', '32822', 'KSCYMOEC-MME-03', '10.148.9.19'), 
                        ('32781', '32822', 'EKRGMD92-vMME-01', '10.88.158.81'), 
                        ('32781', '33033', 'KSCYMOEC-MME-03', '10.148.9.19')], 
                        [('32891', '32822'), ('32822', '32891'), ('32822', '32891'), 
                        ('32822', '32891'), ('32822', '32781'), ('32822', '32781'), 
                        ('32822', '32781'), ('33033', '32891'), ('33033', '32891'), 
                        ('33033', '32891'), ('33033', '32822'), ('33033', '32781'), 
                        ('33033', '32781'), ('33033', '32781'), ('32781', '32891'), 
                        ('32781', '32822'), ('32781', '32822'), ('32781', '33033')]]
        source_list = result_lists[0]
        target_list = result_lists[1]
        combis = result_lists[2]
        print(source_list)
        print(target_list)
        print(combis)

        #for header
        header = ('Source LNBTS', 'Target BTS', 'mmeName', 'Missing IP')
        source_list.insert(0, header)
        target_list.insert(0, header)

        #for writing list of items in Excel
        freq_dict = {x:combis.count(x) for x in combis}
        for i, row in enumerate(source_list, 1):
            #print(row)
            if row[0:2] == ('Source LNBTS', 'Target BTS'):
                result_sheet.append(row)
                source_max_col = result_sheet.max_column
                source_max_row = result_sheet.max_row
            elif row[0:2] != ('Source LNBTS', 'Target BTS'):
                #result_sheet.append(row)
                if freq_dict[row[0:2]] == 1:
                    result_sheet.append(row)
                    source_max_col = result_sheet.max_column
                    source_max_row = result_sheet.max_row
                elif freq_dict[row[0:2]] > 1:
                    result_sheet.append(row[0:2])
                    #print(source_max_col)
                    #result_sheet.insert_cols(source_max_col+1)
                    for j, r in enumerate(row[2:4], -1):
                        if j== -1:
                            j=-1
                        else:
                            j=j+2
                        result_sheet.cell(row=source_max_row, column=source_max_col+j, value=r)
                        source_max_row = result_sheet.max_row