Your description of the code is correct. To get understanding of zip
so, given what start_col and end_col are
I would not use the if else as perfringo - no need to evaluate the if condition 5 times. And with this approach (to pass column and row numbers to merge) you can skip the zip and use list comprehension.
>>> list(zip([2, 4, 6, 8], [3, 5, 7, 9])) [(2, 3), (4, 5), (6, 7), (8, 9)]Note, in python3 it produces zip-object, so I convert to list for you to see what it is, but zip-object is iterable so you don't need to convert it to list in order to iterate over its elements.
so, given what start_col and end_col are
for col1, col2 in zip(start_col, end_col):is same as
for col1, col2 in [(2, 3), (4, 5), (6, 7), (8, 9)]:each element of the list (each is 2-element tuple) is unpacked in the variables. so on first iteration col1=2 and col2=3 and so on.
I would not use the if else as perfringo - no need to evaluate the if condition 5 times. And with this approach (to pass column and row numbers to merge) you can skip the zip and use list comprehension.
columns = [(col, col+1) for col in range(2, 9, 2)] for row in (1, 4): sheet.merge_cells(start_row=row, start_column=1, end_row=row, end_column=9) for row in (2, 3, 5): for col1, col2 in columns: sheet.merge_cells(start_row=row, start_column=col1, end_row=row, end_column=col2)can you show your current code?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs