Skip to content

Commit 12da74e

Browse files
committed
remove the exception handling with a simple if condition to avoid complication and unwanted inefficiencies
1 parent b6e2e46 commit 12da74e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

implement-laptop-allocation/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ class Laptop:
2727

2828

2929
def sadness(person: Person, laptop: Laptop) ->int:
30-
try:
31-
return person.preferred_operating_systems.index(laptop.operating_system)
32-
except ValueError:
30+
if laptop.operating_system in person.preferred_operating_systems:
31+
return person.preferred_operating_systems.index(laptop.operating_system)
3332
return 100
3433

3534

0 commit comments

Comments
 (0)