Add helper functions for List
This commit is contained in:
parent
a9cbd6f67d
commit
bdc9964e47
65
helpers/list_helpers.py
Normal file
65
helpers/list_helpers.py
Normal file
@ -0,0 +1,65 @@
|
||||
from typing import List
|
||||
|
||||
def is_asian_car(car_make: str) -> bool:
|
||||
"""
|
||||
Check if a given car make is from an Asian manufacturer.
|
||||
|
||||
Args:
|
||||
car_make (str): The car make to check.
|
||||
|
||||
Returns:
|
||||
bool: True if the car make is Asian, False otherwise.
|
||||
"""
|
||||
asian_car_makers = [
|
||||
'toyota', 'honda', 'nissan', 'mazda', 'subaru', 'mitsubishi',
|
||||
'suzuki', 'lexus', 'infiniti', 'acura', 'hyundai', 'kia',
|
||||
'genesis', 'ssangyong', 'isuzu', 'daihatsu'
|
||||
]
|
||||
return car_make.lower() in asian_car_makers
|
||||
|
||||
def filter_asian_cars(cars: List[str]) -> List[str]:
|
||||
"""
|
||||
Filter a list of car makes to include only Asian car makes.
|
||||
|
||||
Args:
|
||||
cars (List[str]): A list of car makes.
|
||||
|
||||
Returns:
|
||||
List[str]: A list of Asian car makes.
|
||||
"""
|
||||
return [car for car in cars if is_asian_car(car)]
|
||||
|
||||
def get_asian_car_list() -> List[str]:
|
||||
"""
|
||||
Get a list of common Asian car makes.
|
||||
|
||||
Returns:
|
||||
List[str]: A list of Asian car makes.
|
||||
"""
|
||||
return [
|
||||
'Toyota', 'Honda', 'Nissan', 'Mazda', 'Subaru', 'Mitsubishi',
|
||||
'Suzuki', 'Lexus', 'Infiniti', 'Acura', 'Hyundai', 'Kia',
|
||||
'Genesis', 'SsangYong', 'Isuzu', 'Daihatsu'
|
||||
]
|
||||
|
||||
def sort_asian_cars(cars: List[str]) -> List[str]:
|
||||
"""
|
||||
Sort a list of Asian car makes in alphabetical order.
|
||||
|
||||
Args:
|
||||
cars (List[str]): A list of Asian car makes.
|
||||
|
||||
Returns:
|
||||
List[str]: A sorted list of Asian car makes.
|
||||
"""
|
||||
return sorted(cars)
|
||||
|
||||
def print_asian_cars(cars: List[str]) -> None:
|
||||
"""
|
||||
Print a list of Asian car makes.
|
||||
|
||||
Args:
|
||||
cars (List[str]): A list of Asian car makes.
|
||||
"""
|
||||
for car in cars:
|
||||
print(car)
|
Loading…
x
Reference in New Issue
Block a user