Lists And For Loops Practice Problems | Dataquest
# My answer total = 0 row_sum = 0 for el in matrix: row_sum = sum(el) total += row_sum # DQ's Answer num_rows = len(matrix) num_cols = len(matrix) total = 0 for row in range(num_rows): for col in range(num_cols): total += matrix[row][col]
Wanted to get feedback on whether my code is a better or worse answer to this practice problem. Would appreciate if anyone could point out why mine might be less preferable to the one provided by DQ. The goal here was to sum all the numbers in a nxm matrix. Thanks!