Before iterating through the dictionary on ps8, problem 2, how does one initialize the pair for comparison with iterated pair, or how do you have your logic to avoid this?
So far I have used popitem() to arbitrarily grab one, but I have to add it back since this is destructive. Seems clunky.
... # find 'best' item in remaining dictionary while work < maxWork : try: initial = subjectsCopy.popitem() except KeyError: break bestClass = initial[0] bestPair = initial[1] subjectsCopy[bestClass] = bestPair #put it back for keyClass, valuePair in subjectsCopy.items(): ...
I see others here have used .keys() to get a list and iterate through this. For initialization, you index [0]. This may be more consistent since popitem() is aribtrary, but I don't see anything 'wrong' with what I'm doing...
don't quite understand what you are asking or stating
Join our real-time social learning platform and learn together with your friends!