User Tools

Site Tools


python:fibonacci

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python:fibonacci [2016/01/26 05:34] (current)
admin created
Line 1: Line 1:
 +====== Fibonacci implementation ======
 +26.01.2016
  
 +
 +A good example of iterators and generators.
 +
 +<code python>
 +def fibonacci(n):​
 +    a,b  = 0, 1
 +    while n:
 +        yield a
 +        a, b = b, a + b
 +        n -= 1
 +
 +for x in fibonacci(10):​
 +    print(x,)
 +</​code>​
 +
 +Check the live code [[https://​repl.it/​Bgr7/​0 | here]].
python/fibonacci.txt ยท Last modified: 2016/01/26 05:34 by admin