Skip to content

Instantly share code, notes, and snippets.

@Grokzen
Created July 10, 2013 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grokzen/5968698 to your computer and use it in GitHub Desktop.
Save Grokzen/5968698 to your computer and use it in GitHub Desktop.
Tiny lib that will perform a simple version of fuzzy string matching, similar to what sublime text use.
import difflib
def match(key, search_for):
a = [char for char in search_for]
index = 0
for char in key:
if a[index] == char:
index += 1
if index == len(a):
break
return index == len(a)
def fuzzy_match(keys, search_string):
return [(match(key, search_string.replace(" ", "")), difflib.SequenceMatcher(None, key, search_string.replace(" ", "")).ratio(), key) for key in keys]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment