Congruence of 'map' and 'for' broken in 2.1??

Alexander Semenov sav at ulj.menatepspb.com
Sat Apr 28 06:32:02 EDT 2001


>   >>> print reduce(lambda x, y: x+y, map(int,fh.xreadlines()))
>   Traceback (most recent call last):
>     File "<pyshell#91>", line 1, in ?
>       print reduce(lambda x, y: x+y, map(int,fh.xreadlines()))
>   TypeError: argument 2 to map() must be a sequence object

if you are looking for appropriate one-liner, this works fine:

print reduce(lambda x,y:x+y, [int(x) for x in fh.xreadlines()])

WBR
Alexander Semenov






More information about the Python-list mailing list