Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

editdistance

> 编程语言
Open source

Fast implementation of the edit distance(Levenshtein distance)

705 stars0 likes2 views
WebsiteGitHub

About

Fast implementation of the edit distance(Levenshtein distance)

editdistance

Fast implementation of the edit distance (Levenshtein distance).

This library simply implements Levenshtein distance with C++ and Cython.

The algorithm used in this library is proposed by Heikki Hyyrö, "Explaining and extending the bit-parallel approximate string matching algorithm of Myers", (2001)

Binary wheels

Thanks to pypa/cibuildwheel There are binary wheels on Linux, Mac OS, and Windows.

Install

You can install via pip:

bash
pip install editdistance

Usage

It's quite simple:

python
import editdistance
editdistance.eval('banana', 'bahama')
# 2L

Simple Benchmark

With IPython, I tried several libraries:

  • pyxDamerauLevenshtein
  • pylev
  • python-Levenshtein

On Python 2.7.5:

python
a = 'fsffvfdsbbdfvvdavavavavavava'
b = 'fvdaabavvvvvadvdvavavadfsfsdafvvav'
import pylev
timeit pylev.levenshtein(a, b)
# 100 loops, best of 3: 7.48 ms per loop

from pyxdameraulevenshtein import damerau_levenshtein_distance
timeit damerau_levenshtein_distance(a, b)
# 100000 loops, best of 3: 11.4 µs per loop

timeit editdistance.eval(a, b)  # my library
# 100000 loops, best of 3: 3.5 µs per loop

import Levenshtein

timeit Levenshtein.distance(a, b)
# 100000 loops, best of 3: 3.21 µs per loop

Distance with Any Object

Above libraries only support strings. But Sometimes other type of objects such as list of strings(words). I support any iterable, only requires hashable object of it:

python
Levenshtein.distance(['spam', 'egg'], ['spam', 'ham'])
# ---------------------------------------------------------------------------
# TypeError                                 Traceback (most recent call last)
#  in ()
# ----> 1 Levenshtein.distance(['spam', 'egg'], ['spam', 'ham'])
#
# TypeError: distance expected two Strings or two Unicodes

editdistance.eval(['spam', 'egg'], ['spam', 'ham'])
# 1L

So if object's hash is same, it's same. You can provide __hash__ method to your object instances.

Enjoy!

License

It is released under the MIT license.

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言