Fixing usage of reduce to support Python 3.