-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path03. Cheese Showcase.py
More file actions
44 lines (35 loc) · 1.22 KB
/
Copy path03. Cheese Showcase.py
File metadata and controls
44 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def sorting_cheeses(**kwargs):
'''
The function receives a dictionary with cheeses as keys and lists of pieces as values.
We should return the cheeses and their pieces' as quantities sorted by the number of pieces
of a cheese kind in descending order. If two or more cheeses have the same number of pieces,
we should sort them by their names in ascending order (alphabetically).
For each kind of cheese, we return their pieces quantities in descending order.
'''
sorted_cheeses = sorted(kwargs.items(), key=lambda x: (-len(x[1]), x[0]))
cheeses = []
for cheese, pieces_count in sorted_cheeses:
cheeses.append(cheese)
quantities = sorted(pieces_count, reverse=True)
cheeses += quantities
return '\n'.join([str(cheese) for cheese in cheeses])
# print('---- Documentation ----')
# print(sorting_cheeses.__doc__)
# print()
# print('---- Tests ----')
# print()
# print(
# sorting_cheeses(
# Parmesan=[102, 120, 135],
# Camembert=[100, 100, 105, 500, 430],
# Mozzarella=[50, 125],
# )
# )
# print()
# print(
# sorting_cheeses(
# Parmigiano=[165, 215],
# Feta=[150, 515],
# Brie=[150, 125]
# )
# )