Filling in a tuple from unknown size list

Mel mwilson at the-wire.com
Fri Nov 27 12:47:40 EST 2009


Steven D'Aprano wrote:
> On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote:
>> 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.

> I'd call that a code-smell. If I saw that in code, I'd think long and
> hard about why it was there and if I could eliminate the names a...f and
> just work directly with the list.

It's a common enough thing at the boundaries of your program, letting user 
input in through the gates, as it were.  Deeper in, I agree; that stuff 
should have been dealt with at the gates.
	
	Mel.




More information about the Python-list mailing list