Fix incompatibilities with Python 3

Add Python 2/3 compatible code for izip and reduce.