Functional Pascal triangle in Python (working version)
Your current code calls pascal_row O(n^2) times (put a print inside to see this) through recursion. You don't want to be repeating so much calculation. To cache the results:

from functools import lru_cache

@lru_cache(maxsize=None)
def pascal_row(n):


However then you can't be returning generators anymore because after one iteration they'll be exhausted and yet the caching will return the same generators repeatedly, so you won't get the right results. This is fine, there wasn't really much use in the generators. It was particularly weird to see (x for x in [1]).

You could return list(dispatch()) but there's a much better itertools way than successive yielding: chain.

return list(chain([1], starmap(operator.add, pairwise(pascal_row(n - 1))), [1]))


But really there's no need for all this. The Pythonic way would be:

return [1] + [a + b for a, b in pairwise(pascal_row(n - 1))] + [1]


which is still decently functional.

if n &lt; 2: implies that n might also be 0, -1, etc. You want to:


Make it clear to readers that n should not be that.
Make sure the program quickly ends in an error in such a case so that you can find the bug.


Therefore add an assert n == 1 in this case.

This comes out to:

@lru_cache(maxsize=None)
def pascal_row(n):
    """
    Return a list that yields the nth row of a Pascal triangle
    """
    if n &lt; 2:
        assert n == 1
        return [1]
    else:
        return [1] + [a + b for a, b in pairwise(pascal_row(n - 1))] + [1]


In my opinion the recursion in print_pascal is completely unnecessary and a simple for loop would be much better, but I suppose you want it that way for the exercise.

To be really functional you could ensure that your data structures are immutable and use tuples instead of lists, although it's less pretty:

if n &lt; 2:
    return (1,)
else:
    return (1,) + tuple(a + b for a, b in pairwise(pascal_row(n - 1))) + (1,)