Question: Expected Behavior Wite a program, in a fie namad word _ search. py , to do the folowing: the word - lst fie cortains ond

Expected Behavior
Wite a program, in a fie namad word_search. py, to do the folowing:
the word-lst fie cortains ond word per line,
Examples
The following is an axample of the grid of lettera fie:
]):}):}
hs,e,y,p,k
[1
In tris example (and as your program can figure out atter reading the first line).N=6. For this gid, the worda your program should print out are:
: bode, cod, odo, lob prorizomal, L-to-R)
bow, yes, doc (horizomal, R-to-L)
: spool pool, way (vertical top-to-bottom)
locp, lopa (vertical , botom-to-kop)
lob, wag (diagoral, toplati to bottom-right)
Input files
Output format
The worda you find ahould be printed in alphabatical ordar, one to a line without ary axtra whitespace.
Note: If the gid-ot-latters fie is empty, these is no output.
Development Strategy
Data Structures
Organize the list of valid words as a lats of stringe. Organize the grid as a list of ists.
Program development
Seaching harizontally First, consider the problem of finding words horiaontaly, in the grid going from left to right. Coraider the frst row in the example shown above
ycodej
Neat consider the problem of soarching for worda horizontally going right to left. Suppose we want to search the row y o d e j going right to lett. This is actually the aame as reversing the row, to
iedocy
If you can entract each diagonal into a list of latiors, then you can simply saarch through this ist as you did bofore-again, reducing this probliam to one youlve already writien coda to solve.
Program Structure
The use of a naia() function and supporing functions doscribed above is similar to the structure that was provided to you for the ward_grid. py program
Note: You may not use global variablea.
If you would lixe more guidance on how to structure your program, you may use the outline below:
def get_word_List():
retera a list of valid words
det read_letters_tiles():
reture a grid of letters
wore functions are defined here
naia():
werd_ist = get_word_tist)
letters_-grid - read_lietters_+ile()
call a function that finds the words appearing horizontalty, passing in the needed argunents
call a function that finds the words appearing vertically, passing in the needed arguneents
call a function that finds words appearing on the diagonals, passing in the needed argunents
call a function that prints the words found, passing in the needed argueent(s)
maia()
Examples
The following is an example of the grid of letters file:
In this example (and as your program can figure out after reading the first line),N=6. For this grid, the words your program should print out are:
code, cod, ode, lob (horizontal, L-to-R)
bow, yes, doc (honizontal, R-to-L)
spool, pool, way (vertical, top-to-bottom)
: loop, loops (vertical, bottom-to-top)
Input files
Output format
The words you find should be printed in alphabetical order, one to a line without any extra whitespace.
Note: If the grid-ot-letters file is empty, there is no output.
Development Strategy
Data Structures
Organize the list of valid words as a list of strings. Organize the grid as a list of lists.
Program development
Searching horizontally. First, consider the problem of finding words horizontally in the grid going from left to right. Consider the first row in the example shown above:
ycodej
Next consider the problem of searching for words horizontally going right to left. Suppose we want to search the row y c@d e j going right to left. This is actually the same as reversing the row, to
jedocy
If you can extract each diagonal into a list of letters, then you can simply search through this list as you did before-again, reducing this problem to one you've already written code to solve.
Do you see a pattern in how the x-and y-coordinates change between successive elements? Can you use this pattern to extract a diagonal going from the upper-left to lower-right given its starting coordinates into a list?
Program Structure
The use of a main() function and supporting functions described above is similar to the structure that was provided to you for the word_grid. py program.
Note: You may not use global variables.
If you would like more guidance on how to structure your program, you may use the outine below:
def get_word_list():
return a list of valid words
def read_letters_files():
return a grid of letters
more functions are defined here
...
ef main():
word_list = get_word_list()
letters_grid -= read lett
# a list used to accumulate the valid words found
all_words =[]
call a function that finds the words appearing horizontally, passing
Expected Behavior Wite a program, in a fie namad

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!