def METHOD_NAME(needle, haystack=None):
    try:
        return opened_files[needle]
    except KeyError:
        files = filter(lambda x: x.get_path().rfind(needle) != -1, haystack)
        # Py3: filter returns an iterable, not a list
        file = list(files)[0]
        opened_files[needle] = open(file.get_abspath(), 'w')
        return opened_files[needle]