Port most of the code to Python3 compatible.

The code should still work on Python2.

Import and print are the main changes.

Not everything might be ported. The most part that was left intact are the `range()`. In Python2 it returns a list and in python it returns an iterator. This should speed up and in most cases should work without further changes.

See http://www.diveinto.org/python3/porting-code-to-python-3-with-2to3.html#xrange