def group(db, by):
    '\n    Group the document in the database according to the value of the doc[by] in db.\n\n    Parameters\n    ----------\n    db : iterable\n        The database of documents.\n    by : basestring\n        The key to group the documents.\n\n    Returns\n    -------\n    grouped: dict\n        A dictionary mapping the feature value of group to the list of docs. All docs in the same generator have\n        the same value of doc[by].\n\n    Examples\n    --------\n    Here, we use a tuple of dict as an example of the database.\n    >>> db = ({"k": "v0"}, {"k": "v1"}, {"k": "v0"})\n    >>> group(db)\n    This will return\n    >>> {"v0": [{"k": "v0"}, {"k": "v0"}], "v1": [{"k": "v1"}]}\n    '
    grouped = {}
    doc: dict
    for doc in db:
        key = doc.get(by)
        if (not key):
            print('There is no field {} in {}'.format(by, id_key(doc)))
        elif (key not in grouped):
            grouped[key] = [doc]
        else:
            grouped[key].append(doc)
    return grouped
Group the document in the database according to the value of the doc[by] in db.

Parameters
----------
db : iterable
    The database of documents.
by : basestring
    The key to group the documents.

Returns
-------
grouped: dict
    A dictionary mapping the feature value of group to the list of docs. All docs in the same generator have
    the same value of doc[by].

Examples
--------
Here, we use a tuple of dict as an example of the database.
>>> db = ({"k": "v0"}, {"k": "v1"}, {"k": "v0"})
>>> group(db)
This will return
>>> {"v0": [{"k": "v0"}, {"k": "v0"}], "v1": [{"k": "v1"}]}
def group(db, by):
    '\n    Group the document in the database according to the value of the doc[by] in db.\n\n    Parameters\n    ----------\n    db : iterable\n        The database of documents.\n    by : basestring\n        The key to group the documents.\n\n    Returns\n    -------\n    grouped: dict\n        A dictionary mapping the feature value of group to the list of docs. All docs in the same generator have\n        the same value of doc[by].\n\n    Examples\n    --------\n    Here, we use a tuple of dict as an example of the database.\n    >>> db = ({"k": "v0"}, {"k": "v1"}, {"k": "v0"})\n    >>> group(db)\n    This will return\n    >>> {"v0": [{"k": "v0"}, {"k": "v0"}], "v1": [{"k": "v1"}]}\n    '
    grouped = {}
    doc: dict
    for doc in db:
        key = doc.get(by)
        if (not key):
            print('There is no field {} in {}'.format(by, id_key(doc)))
        elif (key not in grouped):
            grouped[key] = [doc]
        else:
            grouped[key].append(doc)
    return grouped