lukaproject-t0tyz8/helpers/list_helpers.py
2025-03-29 13:40:07 -05:00

61 lines
1.5 KiB
Python

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)