This is [problem 45](https://projecteuler.net/problem=45) from Project Euler:

> 
> Triangle, pentagonal, and hexagonal numbers are generated by the
>  following formulae:
> 
> 
> Triangle Tn = n x (n+1) / 2 1, 3, 6, 10, 15, ...
> 
> 
> Pentagonal Pn = n x (3n−1) / 2 1, 5, 12, 22, 35, ...
>  Hexagonal Hn = n x (2n−1) 1, 6, 15, 28, 45, ...
> 
> 
> It can be verified that T285 = P165 = H143 = 40755.
> 
> 
> Find the next triangle number that is also pentagonal and hexagonal.
> 
> 
> 

Here is my code:

```
def triangle_generator():
    n = 1
    while True:
        t = n * (n + 1) // 2
        yield t
        n += 1

def pentagonal_generator():
    n = 1
    while True:
        p = n * ((3 * n) - 1) // 2
        yield p
        n += 1

def hexagonal_generator():
    n = 1
    while True:
        h = n * ((2 * n) - 1)
        yield h
        n += 1

def tph():
    tg = triangle_generator()
    pg = pentagonal_generator()
    hg = hexagonal_generator()

    tg_temp_list = []
    pg_temp_list = []
    while True:
        h = next(hg)
        t = 0
        p = 0
        while t < h:
            t = next(tg)
            tg_temp_list.append(t)
        while p < h:
            p = next(pg)
            pg_temp_list.append(p)
        if h in tg_temp_list and h in pg_temp_list:
            print("Found! {}".format(h))
        else:
            tg_temp_list = tg_temp_list[-2:]
            pg_temp_list = pg_temp_list[-2:]

```

So, a hexagonal number is yielded, then two temporary lists are populated—one from `triangle_generator()`, and one from `pentagonal_generator()`. Then, it is checked whether the yielded hexagonal number is in both those lists. If not, the temporary lists are emptied, except the last element, another hexagonal number is yielded, and the whole procedure repeats indefinitely.

My question: (Assuming purely mathematical approaches aside) Does Python provide more convenient (Pythonic) ways to implement the `tph()` function?