Add helper functions for List
This commit is contained in:
parent
bd0374e7c7
commit
e2b57e44a3
61
helpers/list_helpers.py
Normal file
61
helpers/list_helpers.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user