Spaces:
Running
Running
File size: 1,237 Bytes
0aa9a49 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from typing import List
from src.constants import COUNTRY_TO_REGION_MAP, LANGUAGE_TO_COUNTRIES_MAP
def get_language_countries(language: str) -> List[str]:
"""Get the list of countries where a language is spoken."""
return LANGUAGE_TO_COUNTRIES_MAP.get(language, ["Unknown"])
def get_language_regions(language: str) -> List[str]:
"""Get the list of African regions where a language is spoken."""
countries = get_language_countries(language)
regions = set()
for country in countries:
region = COUNTRY_TO_REGION_MAP.get(country)
if region:
regions.add(region)
return list(regions) if regions else ["Unknown"]
def get_all_regions() -> List[str]:
"""Get all unique African regions."""
regions = set(COUNTRY_TO_REGION_MAP.values())
return sorted(regions)
def get_languages_by_region(region: str) -> List[str]:
"""Get all languages spoken in a specific African region."""
countries_in_region = [c for c, r in COUNTRY_TO_REGION_MAP.items() if r == region]
languages = set()
for lang, countries in LANGUAGE_TO_COUNTRIES_MAP.items():
if any(c in countries_in_region for c in countries):
languages.add(lang)
return list(languages)
|