dhp.search package

Module contents

search type utilities

dhp.search.fuzzy_distance(needle, straw)

calculate distance between needle and a straw from the haystack.

  • needle (str) – The thing to match
  • straw (str) – The thing to match against

A distance of 0 indicates a search failure on one or more chars in needle. The lower the distance the closer the match, matching earlier and closer together results in a shorter distance.

Return type:


Return a list of elements from haystack, ranked by distance from needle.

  • needle (str) – The thing to match.
  • haystack (list) – A list of strings to match against.

Of strings, ranked by distance, that fuzzy match needle to one

degree or another.

Return type:



corpus = ['django_migrations.py',
assert fuzzy_search('mig', corpus) == ['migrations.py',