itertools.take?

Raymond Hettinger vze4rx4y at verizon.net
Tue Jul 15 05:05:33 CEST 2003


"Dan Williams" <dan at osheim.org> wrote in message
news:vh6q7cl5ifin20 at corp.supernews.com...
> Is there any interest in adding a "Haskellish" take function to
> itertools? I know its easy enough to roll my own, I've been using:
>
> take = lambda iter, n: [x for x in itertools.islice(iter, 0, n)]

I use:

>>> def take(n, seq):
...     return list(islice(seq, n))


> which works, but I was wondering if it was common enough to get into
> itertools?

It made it to the lastest update of the examples in the docs for itertools.
If there is enough demand, it could go into Py2.4


Raymond Hettinger






More information about the Python-list mailing list