liveBook · Manning

Letter insertion

As explained in Learn AI-Assisted Python Programming, Second Edition

Letter insertion is the operation of generating strings by adding one letter at a selected position in an existing string.

Letter insertion generates strings by placing one possible letter at every position in an existing string. In spelling suggestions, this tests whether a missing letter caused the misspelling. section 7.3

A spelling-suggestion process treats insertion as one of three single-letter edits:

  • Try every alphabet letter in every position, including letters already present. section 7.3
  • Keep only generated strings that occur in the collection of correctly spelled words. section 7.3
  • Separate insertion from deleting and changing letters, then combine the subtasks in a larger candidate-generation function. section 7.5.2

Repairing a missing letter

Adding c to sucessful in the appropriate position produces successful. Adding c in other positions produces candidates such as scucessful, which can be rejected when they are not real words. section 7.3

Table 7.2 Examples of the add_letter, delete_letter, and change_letter function
Input String
Strings Returned by add_letter
Strings Returned by delete_letter
Strings Returned by change_letter
cu
acu, bcu, ccu, …, zcu cau, cbu, ccu, …, czu cua, cub, cuc, …, cuz
u, c
au, bu, du, …, zu, ca, cb, cc, …, cz
cad
acad, bcad, ccad, …, zcad caad, cbad, ccad, …, czad caad, cabd, cacd, …, cazd cada, cadb, cadc, …, cadz
ad, cd, ca
aad, bad, dad, …, za cbd, ccd, cdd, …, czd caa, cab, cac, …, caz

Compare add_letter with deletion and replacement across short input strings such as cu and cad. section 7.5.2

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains exhaustive positions and alphabet choices, then assigns insertion to a separate loop-based subtask.
Examples
Uses sucessful to demonstrate successful and tables for inputs such as cu and cad.
What it assumes
Assumes only an input word and a collection of correctly spelled words for candidate filtering.
What you can do after
Build a function that returns every string formed by inserting one alphabet letter anywhere in an input word.
How it connects
Connects letter insertion with spelling suggestions, string processing, and top-down design.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.