Skip to content

Commit 6cedcc3

Browse files
committed
data structures completed day 2
1 parent 6890818 commit 6cedcc3

File tree

1 file changed

+12
-6
lines changed
  • days/07-09-data-structures/code

1 file changed

+12
-6
lines changed

days/07-09-data-structures/code/cars.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
def main():
1515
print(get_all_jeeps(cars))
1616
print(get_first_model_each_manufacturer(cars))
17+
print(get_all_matching_models(cars, grep="CO"))
18+
print(sort_car_models(cars))
1719

1820

1921
def get_all_jeeps(cars: CarsType = cars) -> str:
@@ -39,24 +41,28 @@ def get_first_model_each_manufacturer(cars: CarsType = cars) -> List[str]:
3941
return first_model
4042

4143

42-
43-
def get_all_matching_models(
44-
cars: CarsType = cars, grep: str = DEFAULT_SEARCH
45-
) -> List[str]:
44+
def get_all_matching_models(cars: CarsType = cars, grep: str = DEFAULT_SEARCH) -> List[str]:
4645
"""
4746
Return a list of all models containing the case insensitive
4847
'grep' string which defaults to DEFAULT_SEARCH ('trail').
4948
Sort the resulting sequence alphabetically
5049
"""
51-
pass
50+
trail_models = []
51+
for key in cars.keys():
52+
trail_models.extend(list(filter(lambda x: grep.lower() in x.lower(), cars[key])))
53+
trail_models.sort()
54+
return trail_models
5255

5356

5457
def sort_car_models(cars: CarsType = cars) -> CarsType:
5558
"""
5659
Loop through the cars dict returning a new dict with the
5760
same keys and the values sorted alphabetically.
5861
"""
59-
pass
62+
for key in cars.keys():
63+
cars[key].sort()
64+
cars[key] = cars[key]
65+
return cars
6066

6167

6268
if __name__ == "__main__":

0 commit comments

Comments
 (0)