Question: def locate _ words ( grid: list [ str ] ) - > tuple [ list [ tuple [ int , int ] ] ,

def locate_words(grid: list[str])-> tuple[list[tuple[int, int]], list[tuple[int, int]]]:
"""Given a grid represented as a list of strings, where '.' represents open spaces
and '*' represents filled squares, this function returns a tuple containing two
lists: one list with the starting (x, y) coordinates of across words, and another
list with the starting (x, y) coordinates of down words. A word must be at least
two letters long to be considered.
Parameters:
grid (list of str): A list of strings representing the crossword grid.
Returns locate_words:
tuple: A tuple containing two lists:
1. List of (x, y) coordinates for across words.
2. List of (x, y) coordinates for down words. """
height = len(grid)
width = len(grid[0])
across_words =[]
down_words =[]
for y in range(height):
for x in range(width):
if grid[y][x]=='.' and (x ==0 or grid[y][x -1]=='*'):
if x +1< width and grid[y][x +1]=='.':
across_words.append((x, y))
for y in range(height):
for x in range(width):
if grid[y][x]=='.' and (y ==0 or grid[y -1][x]=='*'):
if y +1< height and grid[y +1][x]=='.':
down_words.append((x, y))
return (across_words, down_words)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!