permuting letters and fairy tales

Bengt Richter bokr at oz.net
Sat Nov 13 10:40:40 EST 2004


On Sat, 13 Nov 2004 08:40:24 -0500, Kent Johnson <kent3737 at yahoo.com> wrote:

>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))
>
Thanks for shaming me into refreshing my acquaintance with the itertools module ;-)
It really deserves to be more than an acquaintance.  It's surprising that itertools
doesn't show up in posted solutions more (Alex's notwithstanding ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list