python 2.6 compatibility: preventing RuntimeError: dictionary changed size during iteration.