make fit for python3

dict.iteritems() does not exist in python3, and the performance hit with items() should not exist with python3 and be marginally with python2

also basestring does not exist with python3, but we can instead check against str. Since we want to do this only in python3, its only used as fallback if basestring raises a nameerror