diff --git a/helpers/list_helpers.py b/helpers/list_helpers.py new file mode 100644 index 0000000..6964da8 --- /dev/null +++ b/helpers/list_helpers.py @@ -0,0 +1,61 @@ +from typing import List + +asian_cars = [ + "Toyota Corolla", + "Honda Civic", + "Nissan Altima", + "Hyundai Sonata", + "Kia Forte", + "Mazda3", + "Subaru Impreza", + "Mitsubishi Lancer", + "Suzuki Swift", + "Lexus RX", + "Infiniti Q50", + "Acura TLX", + "Genesis G80", +] + +def get_asian_cars() -> List[str]: + """ + Returns a list of Asian car models. + """ + return asian_cars + +def filter_asian_cars_by_name(name: str) -> List[str]: + """ + Filters the list of Asian cars by a given name pattern. + + Args: + name (str): The name pattern to filter by. + + Returns: + List[str]: A list of Asian car models matching the name pattern. + """ + filtered_cars = [car for car in asian_cars if name.lower() in car.lower()] + return filtered_cars + +def filter_asian_cars_by_brand(brand: str) -> List[str]: + """ + Filters the list of Asian cars by a given brand. + + Args: + brand (str): The brand to filter by. + + Returns: + List[str]: A list of Asian car models belonging to the specified brand. + """ + filtered_cars = [car for car in asian_cars if brand.lower() in car.lower().split()[0].lower()] + return filtered_cars + +def sort_asian_cars(reverse: bool = False) -> List[str]: + """ + Sorts the list of Asian cars alphabetically. + + Args: + reverse (bool, optional): If True, sort in descending order. Defaults to False. + + Returns: + List[str]: A sorted list of Asian car models. + """ + return sorted(asian_cars, reverse=reverse) \ No newline at end of file