def find_in_tree(tree, key, perfect=False):
if len(key) == <NUM_LIT:0>:<EOL><INDENT>if tree['<STR_LIT>'] is not None:<EOL><INDENT>return tree['<STR_LIT>'], ()<EOL><DEDENT>else:<EOL><INDENT>for i in range(len(tree['<STR_LIT>'])):<EOL><INDENT>if not perfect and tree['<STR_LIT>'][i][<NUM_LIT:0>] == '<STR_LIT:*>':<EOL><INDENT>item, trace = find_in_tree(tree['<STR_LIT>'][i][<NUM_LIT:1>],<EOL>(), perfect)<EOL>return item, (i,) + trace<EOL><DEDENT><DEDENT>raise KeyError(key)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>head, tail = key[<NUM_LIT:0>], key[<NUM_LIT:1>:]<EOL>for i in range(len(tree['<STR_LIT>'])):<EOL><INDENT>if tree['<STR_LIT>'][i][<NUM_LIT:0>] == head ornot perfect and tree['<STR_LIT>'][i][<NUM_LIT:0>] == '<STR_LIT:*>':<EOL><INDENT>try:<EOL><INDENT>item, trace = find_in_tree(tree['<STR_LIT>'][i][<NUM_LIT:1>],<EOL>tail, perfect)<EOL>return item, (i,) + trace<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>raise KeyError(key)<EOL><DEDENT>
Helper to perform find in dictionary tree.