a few extensions for the itertools
Mathias Panzenboeck
e0427417 at student.tuwien.ac.at
Mon Nov 20 03:47:32 EST 2006
Gabriel Genellina wrote:
> At Sunday 19/11/2006 17:35, Mathias Panzenboeck wrote:
>
>> I wrote a few functions which IMHO are missing in python(s itertools).
>>
>> You can download them here:
>> http://sourceforge.net/project/showfiles.php?group_id=165721&package_id=212104
>>
>>
>> isum(iterable, start=0) -> value
>> Returns the sum of the elements of a iterable
>> plus the value of parameter 'start'. When the
>> iterable is empty, returns start.
>
> Isn't the same as the builtin sum?
>
No, because the builtin sum want's a list. This can also handle any kind of iterable, so this would
work:
isum(i**2 for i in xrange(100))
sum would need firs the whole list to be generated:
sum([i**2 for i in xrange(100)])
>> iproduct(iterable, start=0) -> value
>
> As others said, start should be 1
>
Indeed. Can't believe I made that mistake... the mistake is only in the documentation. :)
>> fcain(funct,*functs) -> function(...,***)
>> fcain(f1,f2,...,fn)(*args,*kwargs) equals
>> f1(f2(...fn(*args,*kwargs)))
>
> I don't understand it, nor even the signature. Perhaps it tries to be
> "fchain", function composition? But what has it to do with iterables?
>
Ups, missed out the 'h'. (Also only in the documentation.)
It's like the . operator in haskell:
fchain(f,g,h) is the same like lambda *args,**kwargs: f(g(h(*args,**kwargs)))
More information about the Python-list
mailing list