filter out the results for which function os.path.isdir returns false, substitute the result for locale_dirs. map the locale_dirs elements with mapping function os.path.basename, substitute the result for all_locales.
all_locales = map ( os . path . basename , locale_dirs )