Idiom for default values when unpacking a tuple

Jeff Epler jepler at
Tue Nov 16 18:04:36 CET 2004

A function to pad a tuple to a given length is not hard to write.
[l] * i is empty if i <= 0, otherwise it has i repetitions of l.

def pad(t,l):
    return t + (None,) * (l - len(t))

tup = (1,2)
a, b, c = pad(tup, 3)
print a, b, c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list