def _group(self, obj, val, behavior):
        """ An internal function used for aggregate "group by" operations.
        """
        ns = self.Namespace()
        ns.result = {}
        iterator = self._lookupIterator(val)

        def e(value, index, *args):
            key = iterator(value, index)
            behavior(ns.result, key, value)

        _.each(obj, e)

        if len(ns.result) == 1:
            try:
                return ns.result[0]
            except __HOLE__:
                return list(ns.result.values())[0]
        return ns.result
dataset/ETHPy150Open serkanyersen/underscore.py/src/underscore.py/underscore._group