Possible Duplicate:
Fibonacci numbers, with an one-liner in Python 3?
It may be very easy thing, but I am very new to Python. I came up with this single statement Fibonacci.
[fibs.append(fibs[-2]+fibs[-1]) for i in xrange(1000)]
Not really single statement, though. I need to initialise the list, fibs, before firing this statement i.e. fibs = [0, 1].
Now, I have 2 questions,
How can we get rid of this list initialisation statement,
fibs = [0, 1], in order to make it really single statement?Original statement prints
Nonen times; where n is the number passed inxrange(). Is there any way to avoid that altogether? Or better if the statement can print the series, instead. Then we don't need to printfibsexplicitly.
[Edited]
Or do we have any alternative to list.append() which returns the list it appends to?