Yet another Pascal triangle in Python written in functional programming pattern Here is my implementation of a Pascal program, which is used to print an n-order Pascal triangle. This is actually an exercise I came up with to familiarize myself with Python's Functional Programming Modules.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import operator
from itertools import starmap, tee
from functools import lru_cache


def pairwise(iterable):
    """
    s -&gt; (s0,s1), (s1,s2), (s2,s3), ...
    https://docs.python.org/3/library/itertools.html#itertools-recipes
    """
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)

@lru_cache()
def pascal_row(n):
    """
    Print the nth row of a Pascal triangle
    """
    if n &lt; 2:
        return (x for x in [1])
    else:
        def dispatch():
            yield 1
            yield from starmap(operator.add, pairwise(pascal_row(n-1)))
            yield 1
        return dispatch()


def pascal(n):
    """
    Print an n-order Pascal triangle
    """
    for i in range(1, n):
        print(pascal_row(i))

print([x for x in pascal_row(500)])


Is this the right way of functional programming? Also, I want you to tell me how to make this piece of code clearer :)
If you look at the documentation for lru_cache you'll see that it says that it can save time when an expensive or I/O bound function is periodically called with the same arguments. You keep calling pascal_row with different arguments and the cache will miss all the time. This can be seen if you put this at the end of your program the line:

print(pascal_row.cache_info())

Output:

CacheInfo(hits=0, misses=500, maxsize=128, currsize=128)

The only other thing I'd say is that you don't really need the -*- coding: utf-8 -*- line, UTF8 is the default and that's what you're using anyway.