Real-world use cases for map's None fill-in feature?

Paul Rubin http
Mon Jan 9 05:51:34 EST 2006


"Raymond Hettinger" <python at rcn.com> writes:
> The generator version is plain, simple, boring, and uninspirational.
> But it took only seconds to write and did not require a knowledge of
> advanced itertool combinations.  It more easily explained than the
> versions with zip tricks.

I had this cute idea of using dropwhile to detect the end of an iterable:

it = chain(iterable, repeat(''))
while True:
   row = tuple(islice(it, group_size))
   # next line raises StopIteration if row is entirely null-strings
   dropwhile(lambda x: x=='', row).next()
   yield row



More information about the Python-list mailing list