itertools.take?

D

Dan Williams

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)]

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

-Dan
 
R

Raymond Hettinger

Dan Williams said:
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:
.... 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top