[BangPypers] Issue with list comprehension

Abdul Muneer abdulmuneer at gmail.com
Thu Nov 7 10:11:03 CET 2013


Hi,
"_sum=sum([n for n in itertools.takewhile(lambda x: x < 400, fib)])
TypeError: 'int' object is not callable"

Probably 'sum' might have been used earlier in the code to store the value
of some integer. "sum" is a builtin function but the moment you assign
sum=(x+y) or something, you have lost that function. If you are doubtful,
do `from __builtin__ import * ` to reclaim your builtin variables and
functions.

Regards,
Abdul Muneer

--
Follow me on Twitter: @abdulmuneer <http://twitter.com/#%21/abdulmuneer>


On Thu, Oct 31, 2013 at 12:22 PM, Asokan Pichai <pasokan at gmail.com> wrote:

> import itertools
>
> def fib():
>   a, b = 0, 1
>   while True:
>       yield b
>       a, b = b, a+b
>
> print sum(itertools.takewhile(lambda x: x < 400, fib))
> -----------------------
> I tried the above; and it worked too (986)
>
> Asokan Pichai
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list