A community for students.

    Here's the question you clicked on:

    55 members online
    • 0 replying
    • 0 viewing


    • 2 years ago

    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?

    • This Question is Open
    1. Zaber123
      • 2 years ago
      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 :/

    2. bwCA
      • 2 years ago
      Best Response
      You've already chosen the best response.
      Medals 0


    3. Not the answer you are looking for?
      Search for more explanations.

      • Attachments:

    Ask your own question

    Sign Up
    Find more explanations on OpenStudy
    Privacy Policy

    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.