in reply to string similarity by using a function sort_by_similarity()
Based on your description I suspect that you are trying to compare DNA sequences, either at the level of a codon or translated to protein sequences. If that is the case, much more efficient and robust ways to do this are available. A more complete description of the problem would help.
Recommended next steps: