University of Arizona, Department of Computer Science

CSc 120: Grid is Square

Expected Behavior

Write a function grid_is_square(arglist), where arglist is a list of lists, that returns True if arglist has the shape of a square grid, i.e., if the length of each element (i.e., "row") of arglist is equal to the number of rows of arglist; and False otherwise.

You can assume that arglist is a list of lists, and do not have to check this.

Examples

  1. grid_is_square([[1,2],[3,4]])
    return value: True

  2. grid_is_square([[0,1,2],[3,4]])
    return value: False

  3. grid_is_square([[0,1,2,3,4],[3,4,5,6,7],[4,5,6,7,8]])
    return value: False

  4. grid_is_square([[1]])
    return value: True

  5. grid_is_square([[1,2,3],[3,4,5],[5,6,7]])
    return value: True