Congruence of 'map' and 'for' broken in 2.1??
Alex Martelli
aleaxit at yahoo.com
Sun Apr 29 07:35:10 EDT 2001
"Alexander Semenov" <sav at ulj.menatepspb.com> wrote in message
news:9ce675$2264$1 at news1.simtel.ru...
> > >>> 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()])
...although
print reduce(operator.add, [int(x) for x in fh.xreadlines()])
might be even better.
Alex
More information about the Python-list
mailing list