default value in a list

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Sun Jan 23 02:27:24 EST 2005


Nick Coghlan wrote:
> 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 ;)

I have no intent of doing so, I would leave that to more experienced
people...

Reinhold ;)



More information about the Python-list mailing list