Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
490 B
1
Indexable
Never
# Find the length of the input list
    n = len(input_list)
    # Find the length of each sublist
    m = len(input_list[0])
    # Initialize the output list with empty sublists
    output_list = [[] for _ in range(n+m-1)]
    # Loop through each cell in the input matrix
    for i in range(n):
        for j in range(m):
            # Append the cell to the appropriate diagonal in the output list
            output_list[i-j+n-1].append(input_list[i][j])
    return output_list