Write a function that given the matrix grid, prints all the celebrities.
For example, in the following grid person 2 is a celebrity:
0 1 2 3 -------------- 0 | 1 1 1 0 1 | 0 1 1 0 2 | 0 0 1 0 3 | 1 0 1 1
In the next example no one is a celebrity:
0 1 2 3 4 ---------------- 0 | 1 1 1 0 1 1 | 0 1 1 0 1 2 | 0 0 1 0 0 3 | 1 0 1 1 1 4 | 1 0 0 1 1
Remember: A matrix can be represented as a list-of-lists, where each sub-list is a row of the matrix. For example, the first matrix can be represented as:
grid = [ [ 1 , 1 , 1 , 0 ], [ 0 , 1 , 1 , 0 ], [ 0 , 0 , 1 , 0 ], [ 1 , 0 , 1 , 1 ] ] |
Or you can use multiple lines to define the grid:
grid = [ [ 1 , 1 , 1 , 0 ], [ 0 , 1 , 1 , 0 ], [ 0 , 0 , 1 , 0 ], [ 1 , 0 , 1 , 1 ] ] |
You can test your function with code like the following test cases:
print ( "Test 1, Should show #2 is a celebrity." ) grid = [ [ 1 , 1 , 1 , 0 ], [ 0 , 1 , 1 , 0 ], [ 0 , 0 , 1 , 0 ], [ 1 , 0 , 1 , 1 ] ] check_celebrity(grid) print ( "Test 2, Should show no one is a celebrity." ) grid = [ [ 1 , 1 , 1 , 0 , 1 ], [ 0 , 1 , 1 , 0 , 1 ], [ 0 , 0 , 1 , 0 , 0 ], [ 1 , 0 , 0 , 1 , 1 ], [ 1 , 0 , 0 , 1 , 1 ] ] check_celebrity(grid) print ( "Test 3, Should show #2 is a celebrity." ) grid = [ [ 1 , 1 , 1 , 0 , 1 ], [ 0 , 1 , 1 , 0 , 1 ], [ 0 , 0 , 1 , 0 , 0 ], [ 0 , 0 , 1 , 0 , 1 ], [ 1 , 0 , 1 , 1 , 1 ] ] check_celebrity(grid) print ( "Test 4, Should show no one is a celebrity." ) grid = [ [ 1 , 1 , 1 , 0 , 1 ], [ 0 , 1 , 1 , 0 , 1 ], [ 1 , 0 , 1 , 0 , 0 ], [ 0 , 0 , 1 , 0 , 1 ], [ 1 , 0 , 1 , 1 , 1 ] ] check_celebrity(grid) |