

def test_groupby(self):
    parity = _.groupBy([1, 2, 3, 4, 5, 6], (lambda num, *args: (num % 2)))
    self.assertTrue(((0 in parity) and (1 in parity)), 'created a group for each value')
    self.assertEqual(_(parity[0]).join(', '), '2, 4, 6', 'put each even number in the right group')
    self.assertEqual(_.groupBy([1], (lambda num, *args: num)), [1])
    llist = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
    grouped = _.groupBy(llist, (lambda x, *args: len(x)))
    self.assertEqual(_(grouped[3]).join(' '), 'one two six ten')
    self.assertEqual(_(grouped[4]).join(' '), 'four five nine')
    args.assertEqual(_(grouped[5]).join(' '), 'three seven eight')

dataset/ETHPy150Open serkanyersen/underscore.py/tests/test_collections.py TestCollections.test_groupby/VarMisuse@202/297 `self`->`args`