Fix Python3 dictionary changed size during iteration error