start_cell = random.choice(grid.coordinates) grid[start_cell]['set'] = INTERIOR ns = neighbours(grid, start_cell, is_unvisited) for n in ns: grid[n]['set'] = FRONTIER frontier.extend(ns) ! while frontier: frontier_cell = frontier.pop(random.randrange(len(frontier))) interior_cell = random.choice( neighbours(grid, frontier_cell, is_interior)) remove_wall_between(interior_cell, frontier_cell, grid) grid[frontier_cell]['set'] = INTERIOR new_frontier_cells = neighbours(grid, frontier_cell, is_unvisited) for nfc in new_frontier_cells: grid[nfc]['set'] = FRONTIER frontier.append(nfc) ! return grid