def split_lengths_for_ratios(nitems, *ratios):
    """Return the lengths of the splits obtained when splitting nitems
    by the given ratios"""
    lengths = [int(ratio * nitems) for ratio in ratios]
    i = 1
    while sum(lengths) != nitems and i < len(ratios):
        lengths[-i] += 1
        i += 1
    assert sum(lengths) == nitems, f'{sum(lengths)} != {nitems}\n{ratios}'
    return lengths