def fuzzy_get(possible_keys, approximate_key, default=None, similarity=<NUM_LIT>, tuple_joiner='<STR_LIT:|>',<EOL>key_and_value=False, dict_keys=None):
dict_obj = copy.copy(possible_keys)<EOL>if not isinstance(dict_obj, (Mapping, pd.DataFrame, pd.Series)):<EOL><INDENT>dict_obj = dict((x, x) for x in dict_obj)<EOL><DEDENT>fuzzy_key, value = None, default<EOL>if approximate_key in dict_obj:<EOL><INDENT>fuzzy_key, value = approximate_key, dict_obj[approximate_key]<EOL><DEDENT>else:<EOL><INDENT>strkey = str(approximate_key)<EOL>if approximate_key and strkey and strkey.strip():<EOL><INDENT>if any(isinstance(k, (tuple, list)) for k in dict_obj):<EOL><INDENT>dict_obj = dict((tuple_joiner.join(str(k2) for k2 in k), v) for (k, v) in viewitems(dict_obj))<EOL>if isinstance(approximate_key, (tuple, list)):<EOL><INDENT>strkey = tuple_joiner.join(approximate_key)<EOL><DEDENT><DEDENT>dict_keys = list(set(dict_keys if dict_keys else dict_obj))<EOL>if strkey in dict_keys:<EOL><INDENT>fuzzy_key, value = strkey, dict_obj[strkey]<EOL><DEDENT>else:<EOL><INDENT>strkey = strkey.strip()<EOL>if strkey in dict_keys:<EOL><INDENT>fuzzy_key, value = strkey, dict_obj[strkey]<EOL><DEDENT>else:<EOL><INDENT>fuzzy_key_scores = fuzzy.extractBests(strkey, dict_keys,<EOL>score_cutoff=min(max(similarity * <NUM_LIT> - <NUM_LIT:1>, <NUM_LIT:0>), <NUM_LIT:100>),<EOL>limit=<NUM_LIT:6>)<EOL>if fuzzy_key_scores:<EOL><INDENT>fuzzy_score_keys = []<EOL>for (i, (k, score)) in enumerate(fuzzy_key_scores):<EOL><INDENT>fuzzy_score_keys += [(score * math.sqrt(len(strkey)**<NUM_LIT:2> /<EOL>float((len(k)**<NUM_LIT:2> + len(strkey)**<NUM_LIT:2>) or <NUM_LIT:1>)), k)]<EOL><DEDENT>fuzzy_score, fuzzy_key = sorted(fuzzy_score_keys)[-<NUM_LIT:1>]<EOL>value = dict_obj[fuzzy_key]<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if key_and_value:<EOL><INDENT>if key_and_value in ('<STR_LIT:v>', '<STR_LIT>', '<STR_LIT:value>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return value<EOL><DEDENT>return fuzzy_key, value<EOL><DEDENT>else:<EOL><INDENT>return value<EOL><DEDENT>
r"""Find the closest matching key in a dictionary (or element in a list)

    For a dict, optionally retrieve the associated value associated with the closest key

    Notes:
      `possible_keys` must have all string elements or keys!
      Argument order is in reverse order relative to `fuzzywuzzy.process.extractOne()`
        but in the same order as get(self, key) method on dicts

    Arguments:
      possible_keys (dict): object to run the get method on using the key that is most similar to one within the dict
      approximate_key (str): key to look for a fuzzy match within the dict keys
      default (obj): the value to return if a similar key cannote be found in the `possible_keys`
      similarity (float): fractional similiarity between the approximate_key and the dict key
        (0.9 means 90% of characters must be identical)
      tuple_joiner (str): Character to use as delimitter/joiner between tuple elements.
        Used to create keys of any tuples to be able to use fuzzywuzzy string matching on it.
      key_and_value (bool): Whether to return both the key and its value (True) or just the value (False).
        Default is the same behavior as dict.get (i.e. key_and_value=False)
      dict_keys (list of str): if you already have a set of keys to search,
        this will save this funciton a little time and RAM

    See Also:
      get_similar: Allows nonstring keys and searches object attributes in addition to keys

    Examples:

    >>> fuzzy_get({'seller': 2.7, 'sailor': set('e')}, 'sail') == set(['e'])
    True
    >>> fuzzy_get({'seller': 2.7, 'sailor': set('e'), 'camera': object()}, 'SLR')
    2.7
    >>> fuzzy_get({'seller': 2.7, 'sailor': set('e'), 'camera': object()}, 'I') == set(['e'])
    True
    >>> fuzzy_get({'word': tuple('word'), 'noun': tuple('noun')}, 'woh!', similarity=.3, key_and_value=True)
    ('word', ('w', 'o', 'r', 'd'))
    >>> fuzzy_get({'word': tuple('word'), 'noun': tuple('noun')}, 'woh!', similarity=.9, key_and_value=True)
    (None, None)
    >>> fuzzy_get({'word': tuple('word'), 'noun': tuple('noun')}, 'woh!', similarity=.9,
    ...           default='darn :-()', key_and_value=True)
    (None, 'darn :-()')
    >>> possible_keys = ('alerts astronomy conditions currenthurricane forecast forecast10day geolookup history ' +
    ...                  'hourly hourly10day planner rawtide satellite tide webcams yesterday').split()
    >>> fuzzy_get(possible_keys, "cond")
    'conditions'
    >>> fuzzy_get(possible_keys, "Tron")
    'astronomy'
    >>> df = pd.DataFrame(np.arange(6*2).reshape(2,6), columns=('alpha','beta','omega','begin','life','end'))
    >>> fuzzy_get(df, 'beg')  # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
    0    3
    1    9
    Name: begin, dtype: int...
    >>> fuzzy_get(df, 'get')
    >>> fuzzy_get(df, 'et')[1]
    7
    >>> fuzzy_get(df, 'get')