

def test_indexBy(self):
    parity = _.indexBy([1, 2, 3, 4, 5], (lambda num, *args: ((num % 2) == 0)))
    self.assertEqual(parity[True], 4)
    self.assertEqual(parity[False], 5)
    self.assertEqual(_.indexBy([1], (lambda num, *args: num)), 1)
    llist = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
    grouped = _.indexBy(llist, (lambda x, *args: len(x)))
    self.assertEqual(grouped[3], 'ten')
    self.assertEqual(grouped[4], 'nine')
    self.assertEqual(grouped[5], 'eight')
    array = [1, 2, 1, 2, 3]
    grouped = _.indexBy(array)
    self.assertEqual(grouped[1], 1)
    self.assertEqual(grouped[2], 2)
    self.assertEqual(grouped[3], 3)

dataset/ETHPy150Open serkanyersen/underscore.py/tests/test_collections.py TestCollections.test_indexBy/original