<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># list_2d_transpose.py
"""Transpose a table, i.e., a 2d list that is not ragged."""

def transpose(table):
    """Returns: copy of table with rows and columns swapped

    Precondition: table is a (non-ragged) 2d List"""
    n_rows = len(table)
    n_cols  = len(table[0])  # all rows have same no. cols
    new_table = []           # result accumulator
    for c in range(n_cols):
        row = []             # single row accumulator
        for r in range(n_rows):
            row.append(table[r][c]) # build up new row
        new_table.append(row)       # add new row to new table
    return new_table

d = [[1,2],[3,4],[5,6]]
print("original matrix:")
print(d)
d_v2 = transpose(d)
print("transposed matrix:")
print(d_v2)
</pre></body></html>