Just using `.items()` would make the code simpler and should work on both python 2 and 3.