def fuzzy_retrieval(documents, sources, value, case_sensitive=True):
    "Retrieve a document from the documents where value is compared against\n    multiple potential sources\n\n    Parameters\n    ----------\n    documents: generator\n        The documents\n    sources: iterable\n        The potential data sources\n    value:\n        The value to compare against to find the document of interest\n    case_sensitive: Bool\n        When true will match case (Default = True)\n\n    Returns\n    -------\n    dict:\n        The document\n\n    Examples\n    --------\n    >>> fuzzy_retrieval(people, ['aka', 'name'], 'pi_name', case_sensitive = False)\n\n    This would get the person entry for which either the alias or the name was\n    ``pi_name``.\n\n    "
    for doc in documents:
        returns = []
        for k in sources:
            ret = doc.get(k, [])
            if (not isinstance(ret, list)):
                ret = [ret]
            returns.extend(ret)
        if (not case_sensitive):
            returns = [reti.lower() for reti in returns if isinstance(reti, str)]
            if isinstance(value, str):
                if (value.lower() in frozenset(returns)):
                    return doc
        elif (value in frozenset(returns)):
            return doc
Retrieve a document from the documents where value is compared against
multiple potential sources

Parameters
----------
documents: generator
    The documents
sources: iterable
    The potential data sources
value:
    The value to compare against to find the document of interest
case_sensitive: Bool
    When true will match case (Default = True)

Returns
-------
dict:
    The document

Examples
--------
>>> fuzzy_retrieval(people, ['aka', 'name'], 'pi_name', case_sensitive = False)

This would get the person entry for which either the alias or the name was
``pi_name``.
def fuzzy_retrieval(documents, sources, value, case_sensitive=True):
    "Retrieve a document from the documents where value is compared against\n    multiple potential sources\n\n    Parameters\n    ----------\n    documents: generator\n        The documents\n    sources: iterable\n        The potential data sources\n    value:\n        The value to compare against to find the document of interest\n    case_sensitive: Bool\n        When true will match case (Default = True)\n\n    Returns\n    -------\n    dict:\n        The document\n\n    Examples\n    --------\n    >>> fuzzy_retrieval(people, ['aka', 'name'], 'pi_name', case_sensitive = False)\n\n    This would get the person entry for which either the alias or the name was\n    ``pi_name``.\n\n    "
    for doc in documents:
        returns = []
        for k in sources:
            ret = doc.get(k, [])
            if (not isinstance(ret, list)):
                ret = [ret]
            returns.extend(ret)
        if (not case_sensitive):
            returns = [reti.lower() for reti in returns if isinstance(reti, str)]
            if isinstance(value, str):
                if (value.lower() in frozenset(returns)):
                    return doc
        elif (value in frozenset(returns)):
            return doc