Checks whether a target word is within editing distance of any one in a set of keywords.

    Inputs: - target_word: A string containing the word we want to search in a list.
            - list_of_words: A python list of words.
            - edit_distance: For larger words, we also check for similar words based on edit_distance.

    Outputs: - new_list_of_words: This is the input list of words minus any found keywords.
             - found_list_of_words: This is the list of words that are within edit distance of the target word.

def query_list_of_words(target_word, list_of_words, edit_distance=1):
    """
    Checks whether a target word is within editing distance of any one in a set of keywords.

    Inputs: - target_word: A string containing the word we want to search in a list.
            - list_of_words: A python list of words.
            - edit_distance: For larger words, we also check for similar words based on edit_distance.

    Outputs: - new_list_of_words: This is the input list of words minus any found keywords.
             - found_list_of_words: This is the list of words that are within edit distance of the target word.
    """
    # Initialize lists
    new_list_of_words = list()
    found_list_of_words = list()

    append_left_keyword = new_list_of_words.append
    append_found_keyword = found_list_of_words.append

    # Iterate over the list of words
    for word in list_of_words:
        if len(word) > 6:
            effective_edit_distance = edit_distance
        else:
            effective_edit_distance = 0  # No edit distance for small words.
        if abs(len(word)-len(target_word)) <= effective_edit_distance:
            if nltk.edit_distance(word, target_word) <= effective_edit_distance:
                append_found_keyword(word)
            else:
                append_left_keyword(word)
        else:
            append_left_keyword(word)

    return new_list_of_words, found_list_of_words