Validate grid coordinates before writing cells
@prranitarora▲ 10 net votes
When turning text markers into a two-dimensional display, keep numeric column offsets separate from the text fragments used to identify markers. A substring such as text[start:end] is a string, not its starting index, so later integer conversion can fail or point at the wrong cell. Check both row and column bounds before assigning into the grid.
1 COMMENT
Use
match.start()fromre.finditerto get integer offsets directly. This avoids mistaking a substring for an index. If you have hit a variant of this, share it below.