a few extensions for the itertools

Mathias Panzenboeck e0427417 at student.tuwien.ac.at
Mon Nov 20 03:50:28 EST 2006


Duncan Booth wrote:
> Mathias Panzenboeck <e0427417 at student.tuwien.ac.at> wrote:
> 
>> take(n,iterable) -> iterator
>>      returns a iterator over the first n
>>      elements of the iterator
> 
> Isn't this just the same as itertools.islice(iterable, n) ?
> 

ok, that's true.

>> drop(n,iterable) -> iterable
>>      drops the first n elemetns of iterable and
>>      return a iterator over the rest
> 
> and this looks to be the same as itertools.islice(iterable, n, None)
> 

same here.

> Can you give use cases for 'heads' and 'tails'? I'm curious why you would 
> want them.

I use them in haskell all the time. But in haskell the lists are all "generators".

In haskell you would implement naive string-search like this:

import List
findIndex (isPrefixOf "bla") (tails "dfvbdbblaesre")



More information about the Python-list mailing list