One thought on “Udacity – Intro to Computer Science – Python – Identity Matrix Grid”

  1. I just did this problem, here’s what I got:

    def is_identity_matrix(grid):
    n = len(grid)
    for e in grid:
    if n != len(e):
    return False
    i = 0
    while i < n:
    j = 0
    if grid[i][i] != 1:
    return False
    while j < n:
    if i != j:
    if grid[i][j] != 0:
    return False
    j += 1
    i += 1
    return True

Leave a reply