|
|
|
|
|
by kazinator
724 days ago
|
|
TXR Lisp: (defun edits1 (word)
(hash-list (build
(each ((i 0..(len word)) (j 1))
(let ((le [word 0..i]) (rj [word j..:]) (ri [word i..:]))
(add (join le rj)) ;; deletes
(each ((c "a".."z"))
(add (join le c rj)) ;; replacements
(add (join le c [word i] rj))) ;; prefixes + inserts
(or (empty le) (empty ri) ;; transposes
(add (join [le 0..-1] [ri 0] [le -1] [ri 1..:])))))
(each ((c "a".."z"))
(add (join word c)))))) ;; suffixes
|
|
as a semantic question, is this materializing the whole list (as the python does) or are the `add` calls inserting into the hash table as the loops run, thus eliminating duplicates?