On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote: [...] > So, a few questions. Firstly, is there a stdlib way to find the key > with the lowest corresponding value? In the above map, it would return > 3, because 18 is the lowest value in the list. I want to do this with > a single pass over the dictionary.
In [1]: prime = {2: 20, 3: 18, 5: 20, 7: 21, 11: 22, 13: 26} In [2]: smallest_key = min(prime.iteritems(), key=lambda k_v: k_v[1])[0] In [3]: smallest_key Out[3]: 3 Still trying to figure out your algorithm ... -- http://mail.python.org/mailman/listinfo/python-list