Skip to content

Graphs · stretch

Count the islands

A map is a list of strings where # is land and . is water. Land squares touching up, down, left or right are the same island.

Write islands(grid) returning how many islands there are. Do not change the grid.

Run adds print(islands(["##..", "##..", "..#.", "...#"])) after your code, to try it.

Stuck on the idea rather than the code? The Graphs lesson walks through it.