human
Complete the below
def map_partitions(func, *args, **kwargs):

    ''''Apply a function to every partition across one or more bags.
    Note that all ``Bag`` arguments must be partitioned identically.
    Parameters
    func : callable
    *args, **kwargs : Bag, Item, Delayed, or object
    Arguments and keyword arguments to pass to ``func``.
    Examples
    >>> import dask.bag as db
    >>> b = db.from_sequence(range(1, 101), npartitions=10)
    >>> def div(nums, den=1):
    ...     return [num / den for num in nums]
    Using a python object:
    >>> hi = b.max().compute()
    >>> hi
    100
    >>> b.map_partitions(div, den=hi).take(5)
    (0.01, 0.02, 0.03, 0.04, 0.05)
    Using an ``Item``:
    >>> b.map_partitions(div, den=b.max()).take(5)
    (0.01, 0.02, 0.03, 0.04, 0.05)
    Note that while both versions give the same output, the second forms a
    single graph, and then computes everything at once, and in some cases
    may be more efficient.'
    '''

=====
Write me a the Python code you requested?
assistant
#Here is the Python code you requested.
    name = ('map-partitions-%s-%s' % (funcname(func), tokenize(func, args, kwargs)))
    bags = []
    dsk = {}
    for vals in [args, kwargs.values()]:
        for a in vals:
            if isinstance(a, (Bag, Item, Delayed)):
                dsk.update(ensure_dict(a.dask))
                if isinstance(a, Bag):
                    bags.append(a)
            elif isinstance(a, Base):
                raise NotImplementedError(("dask.bag    doesn't    support    args    of    type    %s" % type(a).__name__))
    if (not bags):
        raise ValueError('At    least    one    argument    must    be    a    Bag.')
    npartitions = {b.npartitions for b in bags}
    if (len(npartitions) > 1):
        raise ValueError('All    bags    must    have    the    same    number    of    partitions.')
    npartitions = npartitions.pop()
    def build_task(n):
        args2 = [((a.name, n) if isinstance(a, Bag) else (a.key if isinstance(a, (Item, Delayed)) else a)) for a in args]
        if any((isinstance(v, (Bag, Item, Delayed)) for v in kwargs.values())):
            vals = [((v.name, n) if isinstance(v, Bag) else (v.key if isinstance(v, (Item, Delayed)) else v)) for v in kwargs.values()]
            kwargs2 = (dict, (zip, list(kwargs), vals))
        else:
            kwargs2 = kwargs
        if (kwargs2 or (len(args2) > 1)):
            return (apply, func, args2, kwargs2)
        return (func, args2[0])
    dsk.update({(name, n): build_task(n) for n in range(npartitions)})
    return_type = set(map(type, bags))
    return_type = (return_type.pop() if (len(return_type) == 1) else Bag)
    return return_type(dsk, name, npartitions)