permuting letters and fairy tales

Kent Johnson kent3737 at yahoo.com
Sat Nov 13 08:40:24 EST 2004


Bengt Richter wrote:
> But it does bring up a general problem of final logic in an iter loop. ISTM it could
> be useful to have an option not to raise StopIteration, but instead keep returning
> a specified sentinel at the end, something like file.read returns '' repeatedly at EOF.

 From the itertools examples:
 >>> def padnone(seq):
...     "Returns the sequence elements and then returns None indefinitely"
...     return chain(seq, repeat(None))

Kent



More information about the Python-list mailing list