Skip to content
Advertisement

Conditionally merge lines in text file

I’ve a text file full of common misspellings and their corrections.

All misspellings, of the same intended word, should be on the same line.

I do have this somewhat done, but not for all misspellings of the same word.

misspellings_corpus.txt (snippet):

JavaScript

Desired:

JavaScript

template: wrong1, wrong2, wrongN->correct


Attempt:

JavaScript
JavaScript

Advertisement

Answer

Store the correct spelling of your words as keys of a dictionary that maps to a set of possible misspellings of that word. The dict is intended for you to easilly find the word you’re trying to correct and the set is to avoid duplicates of the misspellings.

JavaScript

Then you can iterate over your dictionary

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement