Python hash table for fuzzy matching

冷暖自知 提交于 2019-12-01 20:52:42
Jon Clements

It doesn't sound like you want a hash algorithm - instead some form of binary tree. Or even a list which you use the bisect module with. It'd be worth looking at: Python's standard library - is there a module for balanced binary tree?

Another option (depending on your data), would be to use use an in-memory sqlite3 database and create appropriate indices for possible lookups -- but you'll trade performance/memory and SQL syntax for flexibility...

  • Put all data items in a list.
  • Sort the list on the key.
  • Use binary search to efficiently find items where key > 50 or where key.startswith('abc').

Of course, this only pays off if you have really very many data items. If you have not so many, simply loop through the list and apply your condition to every key.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!