@staticmethod
def _filter_categories(d, filters_to_keep, filters_to_remove):
    """
        Filters a dictionary based on certain keywords.
        :param d: dictionary
        :param filters_to_keep: list or string
        :param filters_to_remove: list or string
        :return: filtered dictionary
        """
    filtered_dict = dict(d)
    if filters_to_keep is not None:
        if isinstance(filters_to_keep, str):
            filters_to_keep = filters_to_keep.split()
        for word in filters_to_keep:
            for key, values in d.items():
                if str(key).lower().find(word.lower()) == -1 and str(values
                    ).lower().find(word.lower()) == -1:
                    try:
                        del filtered_dict[key]
                    except KeyError:
                        continue
                else:
                    continue
    if filters_to_remove is not None:
        if isinstance(filters_to_remove, str):
            filters_to_remove = filters_to_remove.split()
        for word in filters_to_remove:
            for key, values in d.items():
                if str(key).lower().find(word.lower()) != -1 or str(values
                    ).lower().find(word.lower()) != -1:
                    try:
                        del filtered_dict[key]
                    except KeyError:
                        continue
                else:
                    continue
    return filtered_dict
