Skip to content

Commit 93904c0

Browse files
committed
n1 completed
1 parent 3a6e1be commit 93904c0

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

days/04-06-collections/challenge.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ def get_movies_by_director(data=movie_csv):
1717
for line in csv.DictReader(file):
1818
try:
1919
director = line['director_name']
20-
title = line['movie_title']
21-
year = line['year']
20+
title = line['movie_title'].replace('\xa0', '')
21+
year = line['title_year']
2222
score = line['imdb_score']
2323
except ValueError:
2424
continue
2525
m = Movie(title=title, year=year, score=score)
26+
print(m)
2627
directors[director].append(m)
2728

2829

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cars = {
2+
'Ford': ['Falcon', 'Focus', 'Festiva', 'Fairlane'],
3+
'Holden': ['Commodore', 'Captiva', 'Barina', 'Trailblazer'],
4+
'Nissan': ['Maxima', 'Pulsar', '350Z', 'Navara'],
5+
'Honda': ['Civic', 'Accord', 'Odyssey', 'Jazz'],
6+
'Jeep': ['Grand Cherokee', 'Cherokee', 'Trailhawk', 'Trackhawk']
7+
}

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from cars import cars
2+
from collections import defaultdict
3+
4+
5+
def main():
6+
print(get_all_jeeps(cars))
7+
print(first_car(cars))
8+
print(name_contains_str(cars))
9+
sort_cars(cars)
10+
11+
12+
def get_all_jeeps(file):
13+
jeeps = file['Jeep']
14+
return jeeps
15+
16+
17+
def first_car(file):
18+
f_cars = []
19+
for manufacturer, car in file.items():
20+
f_cars.append(car[0])
21+
return f_cars
22+
23+
24+
def name_contains_str(file):
25+
selected_cars = []
26+
for cars in file.values():
27+
for car in cars:
28+
if 'Trail' in car:
29+
selected_cars.append(car)
30+
return selected_cars
31+
32+
33+
def sort_cars(file):
34+
new_dict = defaultdict(list)
35+
for maker, s_cars in file.items():
36+
new_dict[maker] = sorted(s_cars)
37+
print(new_dict)
38+
39+
40+
if __name__ == '__main__':
41+
main()
42+
43+
# challenges
44+
# Get all Jeeps
45+
# Get the first car of every manufacturer.
46+
# Get all vehicles containing the string Trail in their names (should work for other grep too)
47+
# Sort the models (values) alphabetically

0 commit comments

Comments
 (0)