py: Consolidate min/max functions into one, and add key= argument.

Addresses issue #811.