def filter_capabilities_by_languages(bears, languages):
 languages = set((language.lower() for language in languages))
 language_bears_capabilities = {language: (set(), set()) for language in languages}
 for section_bears in bears.values():
  for bear in section_bears:
   bear_language = (({language.lower() for language in bear.LANGUAGES} | {'all'}) & languages)
   language = (bear_language.pop() if bear_language else '')
   capabilities = (language_bears_capabilities[language] if language else tuple())
   language_bears_capabilities.update(({language: ((capabilities[0] | bear.can_detect), (capabilities[1] | bear.CAN_FIX))} if language else {}))
 return language_bears_capabilities

def filter_capabilities_by_languages ( bears , languages ) : languages = set ( ( language . lower ( ) for language in languages ) ) language_bears_capabilities = { language : ( set ( ) , set ( ) ) for language in languages } for section_bears in bears . values ( ) : for bear in section_bears : bear_language = ( ( { language . lower ( ) for language in bear . LANGUAGES } | { 'all' } ) & languages ) language = ( bear_language . pop ( ) if bear_language else '' ) capabilities = ( language_bears_capabilities [ language ] if language else tuple ( ) ) language_bears_capabilities . update ( ( { language : ( ( capabilities [ 0 ] | bear . can_detect ) , ( capabilities [ 1 ] | bear . CAN_FIX ) ) } if language else { } ) ) return language_bears_capabilities
filters the bears capabilities by languages .