Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 10 Online
OpenStudy (anonymous):

Hey guys, am working on PSET 8 Q2 now and can't seem to figure out how does one iterate across keys in a dictionary and compare the (value, work) tuple with another similar tuple? I was thinking if not for the weird requirement, it would be relatively easier to just sort the whole dictionary according to your own specifications. (Probably only works for value and work comparisons)

OpenStudy (anonymous):

dictionary.iteritems(): http://docs.python.org/library/stdtypes.html#dict.iteritems you can turn the dictionary into a list of keys and a list of values then work with lists - the indices of the the items in the two lists will correspond to each other http://dpaste.com/789055/

OpenStudy (anonymous):

Yep thanks for the help.. I did in the meantime succeed in 'converting' the dictionary into a list but am not too sure if the list is the same at every execution, esp since the dictionary ain't indexed..

OpenStudy (anonymous):

when the the key, value pairs are converted to lists, the indices of the items in the lists will correspond to their original key:value relationship in the dictionary, regardless of the order that they have in the list.

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!