anonymous
  • anonymous
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?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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 :/
anonymous
  • anonymous
http://dpaste.com/874120/

Looking for something else?

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