Find dictionary items whose key matches a substring

前端 未结 5 464
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 20:28

I have a large dictionary constructed like so:

programs[\'New York\'] = \'some values...\' 
programs[\'Port Authority of New York\'] = \'some values...\' 
pr         


        
5条回答
  •  执笔经年
    2020-12-07 21:07

    This is usually called a relaxed dictionary and it can be implemented efficiently using a suffix tree.

    The memory used by this approach is linear over the keys, which is optimal, and the time of search is linear over the substring length you are searching, which is also optimal.

    I have found this library in python that implements this.

    https://hkn.eecs.berkeley.edu/~dyoo/python/suffix_trees/

提交回复
热议问题