default value in a list

Nick Coghlan ncoghlan at iinet.net.au
Sun Jan 23 01:02:51 EST 2005


Reinhold Birkenfeld wrote:
>>Why not put these together and put it in itertools, since the requirement seems 
>>to crop up every other week?
>>
>>  >>> line = "A:B:C".split(":")
>>  ...
>>  >>> def ipad(N,iterable, default = None):
>>  ...     return it.islice(it.chain(iterable, it.repeat(default)), N)
>>  ...
>>  >>> a,b,c,d = ipad(4,line)
>>  >>> a,b,c,d
>>('A', 'B', 'C', None)
> 
> 
> Good idea!
> 
> (+1 if this was posted on python-dev!)

Please, please Google the python-dev archives before doing so ;)

Cheers,
Nick.
I seem to recall 'tuple unpacking' as the appropriate phrase. . .

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list