Accessing Python dict values with the key start characters

后端 未结 7 1545
南笙
南笙 2020-12-28 13:56

I was wondering: would it be possible to access dict values with uncomplete keys (as long as there are not more than one entry for a given string)? For example:



        
7条回答
  •  半阙折子戏
    2020-12-28 14:04

    There's a nice and clever implementation of a 'fuzzy' dictionary in pywinauto - this might be perfect for what you need here.

    https://code.google.com/p/pywinauto/source/browse/pywinauto/fuzzydict.py

    and docs here: http://pywinauto.googlecode.com/hg/pywinauto/docs/code/pywinauto.fuzzydict.html

    (edit: although if you specifically want to match from the beginning of the key, you might need to replace SequenceMatcher logic with your custom code)

提交回复
热议问题