fork download
  1. import itertools
  2.  
  3. def fib():
  4. a, b = 0, 1
  5. while True:
  6. yield a
  7. a, b = b, a+b
  8.  
  9. print list(itertools.islice(fib(), 20))
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]