I am working with a spreadsheet where I have to combine all possible combinations of comma-separated values into their own lines. Below is the main logic for the current implementation.
sheet_data = []
for sheetname, sheetdata in excel_content.items():
for irow, row in enumerate(sheetdata.values):
for a in str(row[5]).split(','):
for b in str(row[17]).split(','):
for c in str(row[21]).split(','):
for d in str(row[24]).split(','):
for e in str(row[27]).split(','):
for f in str(row[33]).split(','):
sheet_data.append(
[row[0], row[1], row[2], row[3], row[4], a, row[6], row[7], row[8], row[9], row[10],row[11], row[12], row[13], row[14], row[15], row[16], b, row[18], row[19], row[20],c, row[22], row[23], d, row[25], row[26], e, row[28], row[29], row[30], row[31],row[32], f, row[34], row[35], row[36], row[37], row[38], row[39], row[40], row[41],row[42], row[43], row[44], row[45], row[46], row[47], row[48], row[49], row[50],row[51], row[52], row[53], row[54], row[55], row[56], row[57], row[58]])
Is there any way I could re-write this to be more re-usable and dynamic? What if I need to add a new column to also combine? That'd mean that I would need to create a new for-loop.