Beispiel #1
0
 def test_arg_max(self):
     t1 = ('one', 1)
     t2 = ('two', 2)
     t3 = ('three', 3)
     t4 = ('four', 4)
     ts = [t2, t1, t3, t4]
     arg_max = util.arg_max(ts, lambda x: x[0])
     print "arg max:", arg_max
     self.assertEqual(arg_max, t2)
     self.assertEqual(util.arg_max(ts, lambda x: x[1]), t4)
     t = {'a': 1, 'b': 2, 'c': 3, 'd': 1}
     arg_max = util.arg_max(t.viewitems(), lambda x: x[1])
     self.assertEqual(arg_max[0], 'c')