Sometimes, if I have a generator that I happen to know is non-empty, and I want to get at the first element, I’ll write code like this:

output = next(f for f in os.listdir(dir) if f.endswith('.o'))