Now that we have `next()`, it is possible to write this using generators

```python
def which(program):
    paths = (os.path.join(path, program) for path in os.environ.get('PATH', '').split(os.pathsep))
    matches = (os.path.realpath(p) for p in paths if os.path.exists(p))
    return next(matches, None)
```