Fate of itertools.dropwhile() and itertools.takewhile()

Arnaud Delobelle arnodel at googlemail.com
Thu Jan 3 14:04:06 EST 2008


On Jan 3, 4:39 pm, "win... at gmail.com" <win... at gmail.com> wrote:
> On Dec 29 2007, 11:10 pm, Raymond Hettinger <pyt... at rcn.com> wrote:
>
> > I'm considering deprecating these two functions and would like some
> > feedback from the community or from people who have a background in
> > functional programming.
>
> Well I have just this minute used dropwhile in anger, to find the next
> suitable filename when writing database dumps using date.count names:
>
>     filename = "%02d-%02d-%d" % (now.day, now.month, now.year)
>     if os.path.exists(filename):
>         candidates = ("%s.%d" % (filename, x) for x in count(1))
>         filename = dropwhile(os.path.exists, candidates).next()
>
> Much clearer than the alternatives I think, please keep dropwhile and
> takewhile in itertools ;)

Wouldn't using ifilterfalse instead of dropwhile produce the same
result?

--
Arnaud



More information about the Python-list mailing list