Idiom for default values when unpacking a tuple
Jeff Epler
jepler at unpythonic.net
Tue Nov 16 12:04:36 EST 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
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041116/3df1ddb8/attachment.sig>
More information about the Python-list
mailing list