#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

def fab(max):
    a, b = 0, 1
    while a < max:
        yield b
        a, b = b, a + b

def fibonacci(num):
    a, b = 0, 1
    for i in range(num):
        yield b
        a, b = b, a + b

for i in fab(20):
    print i,
print ''
for i in fibonacci(6):
    print i,
print ''

def fib(max):
    n, a, b = 0, 0, 1
    while n < max:
        yield b
        a, b = b, a + b
        n = n + 1
    # return 'fibonacci done'

# for n in fib(8):
#     print n,
g = fib(6)
while True:
    try:
        x = next(g)
        print('g:', x)
    except StopIteration as e:
        print 'Generator return value:', e
        break

def triangles():
    a = [1]
    while True:
        yield a
        a = [sum(i) for i in zip([0] + a, a + [0])]

n = 0
for t in triangles():
    print(t)
    n = n + 1
    if n == 10:
        break
