Like a groupby but expect the key_fn to return multiple keys for
        each element.
7503
def multi_groupby(self, key_fn):
        
        result_dict = defaultdict(list)

        for x in self:
            for key in key_fn(x):
                result_dict[key].append(x)

        # convert result lists into same Collection type as this one
        return {
            k: self.clone_with_new_elements(elements)
            for (k, elements)
            in result_dict.items()
        }
616362
def collection_keys(coll, sep='.'):
    
    def _keys(x, pre=''):
        for k in x:
            yield (pre + k)
            if isinstance(x[k], dict):
                for nested in _keys(x[k], pre + k + sep):
                    yield nested

    return list(_keys(coll.find_one()))
849840
def get_group_key_line(self, data, key):
        
        idx = -1
        for i, line in enumerate(data.splitlines()):
            if isin_start(self.groups[key], line):
                idx = i
        return idx
1366462
def group_by_key_impl(sequence):
    
    result = {}
    for element in sequence:
        if result.get(element[0]):
            result.get(element[0]).append(element[1])
        else:
            result[element[0]] = [element[1]]
    return six.viewitems(result)
1130358
def _int_to_key(keys, index):
    ''
    if isinstance(index, int):
        try:
            return keys[index]
        except IndexError:
            # use KeyError rather than IndexError for compatibility
            raise KeyError('Index out of range of keys: %s' % (index,))
    return index
904022
def distinct(self, key=lambda x: x):
        
        return Enumerable(self.group_by(key=key).select(lambda g: g.first()).to_list())
836198
function groupBy(keySelector, elementSelector, resultSelector, keyComparator) {
                            __assertFunction(keySelector);
                            __assertFunction(elementSelector);
                            __assert(__isUndefined(resultSelector) || __isFunction(resultSelector), 'resultSelector must be undefined or function!');
                            __assertFunction(keyComparator);
                            var groups = new Map();
                            var result = void 0;
                            var _iteratorNormalCompletion15 = true;
                            var _didIteratorError15 = false;
                            var _iteratorError15 = undefined;

                            try {
                                for (var _iterator15 = self[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {
                                    var val = _step15.value;

                                    // Instead of checking groups.has we use our custom function since we want to treat some keys as equal even if they aren't for the Map
                                    var key = __Collection.__getEqualKey(groups, keySelector(val), keyComparator);
                                    var elem = elementSelector(val);
                                    if (groups.has(key)) {
                                        groups.get(key).push(elem);
                                    } else {
                                        groups.set(key, [elem]);
                                    }
                                }
                            } catch (err) {
                                _didIteratorError15 = true;
                                _iteratorError15 = err;
                            } finally {
                                try {
                                    if (!_iteratorNormalCompletion15 && _iterator15.return) {
                                        _iterator15.return();
                                    }
                                } finally {
                                    if (_didIteratorError15) {
                                        throw _iteratorError15;
                                    }
                                }
                            }

                            if (resultSelector) {
                                // If we want to select the final result with the resultSelector, we use the built-in Select function and retrieve a new Collection
                                result = __Collection.from(groups).select(function (g) {
                                    return resultSelector.apply(undefined, _toConsumableArray(g));
                                });
                            } else {
                                // our result is just the groups -> return the Map
                                result = groups;
                            }
                            return result;
                        }
229041
def _filter_keys(d: dict, keys: set) -> dict:
        
        return {key: d[key] for key in keys if key in d}
422499
def DictKeyColumns(d):
    ''
    return [ColumnItem(k, k, type=deduceType(d[k])) for k in d.keys()]
1071
def nested_get(dictionary, keys):
    
    return reduce(lambda d, k: d[k], keys, dictionary)
715524
def grouper(n, iterable):
    
    return (iterable[i:i + n] for i in range(0, len(iterable), n))
519328
def _group(self, obj, val, behavior):
        
        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 KeyError:
                return list(ns.result.values())[0]
        return ns.result
495112
def keylist(self):
        """"""
        items = self.enumerations.items()
        items.sort(lambda a, b: self.cmp(a[1], b[1]))

        # last item has highest value
        rslt = [None] * (items[-1][1] + 1)

        # map the values
        for key, value in items:
            rslt[value] = key

        # return the result
        return rslt
1165027
def _gotitem(self, key, ndim, subset=None):
        
        # create a new object to prevent aliasing
        if subset is None:
            subset = self.obj

        # we need to make a shallow copy of ourselves
        # with the same groupby
        kwargs = {attr: getattr(self, attr) for attr in self._attributes}

        # Try to select from a DataFrame, falling back to a Series
        try:
            groupby = self._groupby[key]
        except IndexError:
            groupby = self._groupby

        self = self.__class__(subset,
                              groupby=groupby,
                              parent=self,
                              **kwargs)
        self._reset_cache()
        if subset.ndim == 2:
            if is_scalar(key) and key in subset or is_list_like(key):
                self._selection = key
        return self
736488
def distinct(iterable, keyfunc=None):
    '''
    '''
    seen = set()
    for item in iterable:
        key = item if keyfunc is None else keyfunc(item)
        if key not in seen:
            seen.add(key)
            yield item
172554
def group_singles2array(input, **params):
    
    PARAM_FIELD_KEY = 'field.key'
    PARAM_FIELD_ARRAY = 'field.array'
    PARAM_FIELD_SINGLE = 'field.single'

    field_key = params.get(PARAM_FIELD_KEY) if PARAM_FIELD_KEY in params else None
    field_array = params.get(PARAM_FIELD_ARRAY)
    field_single = params.get(PARAM_FIELD_SINGLE)

    if not field_key:
        res = []
        for item in input:
            res.append(item[field_single])
        return {field_array: res}
    else:
        tdict = {}
        for row in input:
            if not row[field_key] in tdict:
                tdict.update({row[field_key]: [row[field_single]]})
            else:
                tdict[row[field_key]].append(row[field_single])
        res = []
        for key, value in tdict.items():
            res.append({field_key: key, field_array: value})
        return res
1206794
def _group(self, rdd):
        """"""
        return rdd.reduceByKey(lambda x, y: x.append(y))