Skip to content

Commit 1a1015a

Browse files
authored
Update dictionary_return_type_example.py
1 parent c13c9d7 commit 1a1015a

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
game_stock = {"Dragon Quest": 5, "Final Fantasy": 1, "Age of Empires": 5}
22

33

4-
def get_highest_stock_games() -> dict[str, int]:
5-
stock_quantities = game_stock.values()
6-
high = 0
7-
for quantity in stock_quantities:
8-
if quantity > high:
9-
high = quantity
10-
game_results = {}
11-
12-
for game in game_stock:
13-
if game_stock[game] == high:
14-
game_results[game] = high
15-
return game_results
16-
17-
18-
print(f"Games with the highest stock: {get_highest_stock_games()}")
4+
def get_highest_stock_games(game_stock: dict[str, int]) -> dict[str, int]:
5+
max_quantity = max(game_stock.values())
6+
return {game: quantity for game, quantity in game_stock.items()
7+
if quantity == max_quantity}
8+
9+
print(f"Games with the highest stock: {get_highest_stock_games(game_stock)}")

0 commit comments

Comments
 (0)