Did I find the right examples for you? yes no

All Samples(2)  |  Call(2)  |  Derive(0)  |  Import(0)
Pads a sequence out to n elements,

filling in with a default value if it is not long enough.

If the input sequence is longer than n, raises ValueError.

Details, details:
This returns a new list; it does not extend the original sequence.
The new list contains the values of the original sequence, not copies.

        def padTo(n, seq, default=None):
    """Pads a sequence out to n elements,

    filling in with a default value if it is not long enough.

    If the input sequence is longer than n, raises ValueError.

    Details, details:
    This returns a new list; it does not extend the original sequence.
    The new list contains the values of the original sequence, not copies.
    """

    if len(seq) > n:
        raise ValueError, "%d elements is more than %d." % (len(seq), n)

    blank = [default] * n

    blank[:len(seq)] = list(seq)

    return blank
        


src/z/o/zope.app.twisted-3.5.0/src/twisted/python/usage.py   zope.app.twisted(Download)
 
        for flag in flags:
            long, short, doc = util.padTo(3, flag)
            if not long:
                raise ValueError, "A flag cannot be without a name."
 
        for parameter in parameters:
            long, short, default, doc = util.padTo(4, parameter)
            if not long:
                raise ValueError, "A parameter cannot be without a name."