py3: use env to select python
py3: convert print to a function
py3: use 'as' for handling exceptions
py3: handle iteritems

dict.iteritems is deprecated. Create a function to decide
whether to use iteritems or iter(items)
py3: handle itervalues

itervalues is deprecated. Create a function to decided
whether to use itervalues or iter(values)
lose the use of map

replace with lists and generators