make it work with Python 3

Not a perfect modification for working on both Python 2 and 3, but it does run on Python 2.7 and 3.3.

I don't have <2.7 to test, I pretty sure it's break since I remove the `nested`, it probably is best to literally nest, but I don't want to add another indentation level. Also `xrange` and `iter*`, I just simply edited with Python 3's.