Fix for clean_dict on Python 3: "dictionary changed size during iteration"