[BangPypers] Issue with list comprehension

2013-10-30 Thread Anant
Hi folks, I am new to Python (have been on Java for 8 years), but I have quickly grasped its style. While working on a problem (as Python practice) to generate fibonacci numbers using generators and list comprehension, I ran into an issue. Here's my code: *import itertools* * * *def fibonacci()

Re: [BangPypers] Issue with list comprehension

2013-10-30 Thread Dhananjay Nene
Thats surprising. The code runs just fine http://ideone.com/06qjoM (Ans: 986) As an aside I renamed _sum to sum_ When avoiding naming conflicts, its recommended to postfix a underscore Prefixing an underscore is to provide a hint that the value that gets assigned to the variable is going to be

Re: [BangPypers] Issue with list comprehension

2013-10-30 Thread Asokan Pichai
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 lis

Re: [BangPypers] Issue with list comprehension

2013-11-07 Thread Abdul Muneer
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 t