Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (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?

OpenStudy (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 :/

OpenStudy (anonymous):

http://dpaste.com/874120/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!