We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 06edbaf commit aa93e55Copy full SHA for aa93e55
greedy_methods/fractional_knapsack.py
@@ -26,9 +26,13 @@ def frac_knapsack(
26
>>> frac_knapsack([10, 40, 30, 50], [5, 4, 6, 3], 8, 4)
27
95.0
28
>>> frac_knapsack([10, 40, 30, 50], [5, 4, 6], 8, 4)
29
- 60.0
+ Traceback (most recent call last):
30
+ ...
31
+ ValueError: zip() argument 2 is shorter than argument 1
32
>>> frac_knapsack([10, 40, 30], [5, 4, 6, 3], 8, 4)
33
34
35
+ ValueError: zip() argument 2 is longer than argument 1
36
>>> frac_knapsack([10, 40, 30, 50], [5, 4, 6, 3], 0, 4)
37
0
38
>>> frac_knapsack([10, 40, 30, 50], [5, 4, 6, 3], 8, 0)
@@ -48,7 +52,7 @@ def frac_knapsack(
48
52
"""
49
53
50
54
# sort in descending order of value/weight ratio
51
- r = sorted(zip(values, weights),
55
+ r = sorted(zip(values, weights, strict=True),
56
key=lambda x: x[0] / x[1], reverse=True)
57
58
values, weights = [i[0] for i in r], [i[1] for i in r] # unzip the list
0 commit comments