Avoid mutating a dict during fast enumeration

Fixes #1843
Merge pull request #1854 from quicksilver/i1843

Avoid mutating a dict during fast enumeration