Fix compatibility with Python 3 using dict.items() instead of dict.iteritems()