Skip to content

NW | 26-SDC-Mar | Ahmad Hmedan | Sprint 5 | Implement laptop allocation#508

Open
AhmadHmedann wants to merge 2 commits intoCodeYourFuture:mainfrom
AhmadHmedann:Implement-laptop-allocation
Open

NW | 26-SDC-Mar | Ahmad Hmedan | Sprint 5 | Implement laptop allocation#508
AhmadHmedann wants to merge 2 commits intoCodeYourFuture:mainfrom
AhmadHmedann:Implement-laptop-allocation

Conversation

@AhmadHmedann
Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

fix: complete laptop allocation logic and resolve typing issues

  • Implement sadness matrix based on user OS preferences
  • Generate all valid laptop assignments using permutations
  • Compute total sadness for each case and select optimal assignment

Questions

Hi, I ran into an issue while building the allocation.

When I tried to use Person as a key in a dictionary like this:
results[person] = laptops[best_perm[index]]

I got this error:
TypeError: unhashable type: 'list'

I worked around it by using person.name as the key instead.

Could you explain why this happens, and what the correct approach should be?

@AhmadHmedann AhmadHmedann added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 21, 2026
Copy link
Copy Markdown

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of language issues, and a major scalability issue

best_perm = perm
results = {}
for index, person in enumerate(people):
results[person.name] = laptops[best_perm[index]]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've declared the function as a dictionary with a key of Person, but you're using the name as the key. You need to be consistent.


best_perm = None
min_sadness = 100000000000
for perm in permutations(range(how_many_laptops)):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you've got 15 laptops, how many times do this loop iterate?

def sadness(person: Person, operating_system: OperatingSystem) -> int:
sad: int = 100
for index, os in enumerate(person.preferred_operating_system):
if os == operating_system:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider preferred_operating_system.index() ?

matrix[i][j] = sadness(person, laptop.operating_system)

best_perm = None
min_sadness = 100000000000
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float('inf') is an option

manufacturer="Dell",
model="XPS",
screen_size_in_inches=15,
operating_system=OperatingSystem.MACOS,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Dell running MACOS? Impressive

@OracPrime OracPrime added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants