Filling in a tuple from unknown size list
Stefan Behnel
stefan_ml at behnel.de
Fri Nov 27 08:48:46 EST 2009
boblatest, 27.11.2009 13:18:
> Here's my question: Given a list of onknown length, I'd like to be
> able to do the following:
>
> (a, b, c, d, e, f) = list
>
> If the list has fewer items than the tuple, I'd like the remaining
> tuple elements to be set to "None". If the list is longer, I'd like
> the excess elements to be ignored.
What about this:
fillUp = [None] * 6
(a, b, c, d, e, f) = (list + fillUp)[:6]
Stefan
More information about the Python-list
mailing list