MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / place_word

Function place_word

backtracking/crossword_puzzle_solver.py:36–56  ·  view source on GitHub ↗

Place a word at the given position. >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''] ... ] >>> place_word(puzzle, 'word', 0, 0, True) >>> puzzle [['w', '', '', ''], ['o', '', '', ''], ['r',

(
    puzzle: list[list[str]], word: str, row: int, col: int, vertical: bool
)

Source from the content-addressed store, hash-verified

34
35
36def place_word(
37 puzzle: list[list[str]], word: str, row: int, col: int, vertical: bool
38) -> None:
39 """
40 Place a word at the given position.
41
42 >>> puzzle = [
43 ... ['', '', '', ''],
44 ... ['', '', '', ''],
45 ... ['', '', '', ''],
46 ... ['', '', '', '']
47 ... ]
48 >>> place_word(puzzle, 'word', 0, 0, True)
49 >>> puzzle
50 [['w', '', '', ''], ['o', '', '', ''], ['r', '', '', ''], ['d', '', '', '']]
51 """
52 for i, char in enumerate(word):
53 if vertical:
54 puzzle[row + i][col] = char
55 else:
56 puzzle[row][col + i] = char
57
58
59def remove_word(

Callers 1

solve_crosswordFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected