Skip to content

Commit 40b845e

Browse files
committed
added part 12
1 parent e58973d commit 40b845e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

part12/01_remaining_stock.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def sort_by_remaining_stock(items: list):
2+
3+
def order_by_remaining_stock(items: tuple):
4+
return items[-1]
5+
6+
return sorted(items, key=order_by_remaining_stock)

part12/02_seasons.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
def sort_by_seasons(items: list):
3+
4+
def order_by_season(items: dict):
5+
return items['seasons']
6+
7+
return sorted(items, key=order_by_season)
8+
9+
10+
11+
if __name__ == "__main__":
12+
shows = [{ "name": "Dexter", "rating" : 8.6, "seasons":9 }, { "name": "Friends", "rating" : 8.9, "seasons":10 }, { "name": "Simpsons", "rating" : 8.7, "seasons":32 } ]
13+
14+
for show in sort_by_seasons(shows):
15+
print(f"{show['name']} {show['seasons']} seasons")

part12/03_ratings.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
def sort_by_ratings(items: list):
3+
4+
def order_by_rating(item: dict):
5+
return item['rating']
6+
7+
return sorted(items, key=order_by_rating, reverse=True)

0 commit comments

Comments
 (0)