Make compatible with Python 3 (dict.keys is a view)