File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
days/07-09-data-structures/code Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 14
14
def main ():
15
15
print (get_all_jeeps (cars ))
16
16
print (get_first_model_each_manufacturer (cars ))
17
+ print (get_all_matching_models (cars , grep = "CO" ))
18
+ print (sort_car_models (cars ))
17
19
18
20
19
21
def get_all_jeeps (cars : CarsType = cars ) -> str :
@@ -39,24 +41,28 @@ def get_first_model_each_manufacturer(cars: CarsType = cars) -> List[str]:
39
41
return first_model
40
42
41
43
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 ]:
46
45
"""
47
46
Return a list of all models containing the case insensitive
48
47
'grep' string which defaults to DEFAULT_SEARCH ('trail').
49
48
Sort the resulting sequence alphabetically
50
49
"""
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
52
55
53
56
54
57
def sort_car_models (cars : CarsType = cars ) -> CarsType :
55
58
"""
56
59
Loop through the cars dict returning a new dict with the
57
60
same keys and the values sorted alphabetically.
58
61
"""
59
- pass
62
+ for key in cars .keys ():
63
+ cars [key ].sort ()
64
+ cars [key ] = cars [key ]
65
+ return cars
60
66
61
67
62
68
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments