Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Zaber123 Group Title

I'm having an issue in Problem Set 9: How do we sort the dictionary given to the 'greedyAdvisor' function so that we can properly implement the greedy algorithm. To me it seems as if the easiest way would be to create a class 'Course' that has attributes of Subject, Value, and Work. Then we could create a list of the Courses found in the dictionary given to the function. However, this is sidestepping the assignment and does not make use of the comparator functions. I want to stick to the guidelines of the assignment. Is there some way to use the sorted function with the comparators as the key. ie. "sorted(subjects, key = cmpWork...)". Or perhaps it would be best to implement the comparators into a manual bubble or merge sort?

  • one year ago
  • one year ago

  • This Question is Open
  1. Zaber123 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I found a workaround answer: 'sortedSubjects = sorted(subjects.items(), key=lambda e: e[1][attr])' I have an if statement before that assigns 'attr' to point at either the value or work attribute in the tuple. I would still like to know the intention of the comparator functions however. I wish the solutions posted matched the questions posed in the problem set :/

    • one year ago
  2. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0


    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.