products/Sources/formale Sprachen/C/Firefox/python/mozbuild/mozbuild/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 1 kB image not shown  

 chunkify.py

  Interaktion und
PortierbarkeitPython
 

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

# This file is a direct clone of
https://github.com/bhearsum/chunkify/blob/master/chunkify/__init__.py
# of version 1.2. Its license (MPL2) is contained in repo root LICENSE file.
# Please make modifications there where possible.

from itertools import islice


class ChunkingError(Exception):
    pass


def split_evenly(n, chunks):
    """Split an integer into evenly distributed list

    >>> split_evenly(73)
    [322]

    >>> split_evenly(123)
    [444]

    >>> split_evenly(3510)
    [4444433333]

    >>> split_evenly(12)
    Traceback (most recent call last):
        ...
    ChunkingError: Number of chunks is greater than number

    """
    if n < chunks:
        raise ChunkingError("Number of chunks is greater than number")
    if n % chunks == 0:
        # Either we can evenly split or only 1 chunk left
        return [n // chunks] * chunks
    # otherwise the current chunk should be a bit larger
    max_size = n // chunks + 1
    return [max_size] + split_evenly(n - max_size, chunks - 1)


def chunkify(things, this_chunk, chunks):
    if this_chunk > chunks:
        raise ChunkingError("this_chunk is greater than total chunks")

    dist = split_evenly(len(things), chunks)
    start = sum(dist[: this_chunk - 1])
    end = start + dist[this_chunk - 1]

    try:
        return things[start:end]
    except TypeError:
        return islice(things, start, end)

Messung V0.5 in Prozent
C=84 H=100 G=92

¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.13Angebot  (Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-23) ¤

*Eine klare Vorstellung vom Zielzustand






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.