Use non-lazy enumeration for removal of dictionary keys.

In the current situation, iterating over `self.data.keys()` is OK only when
the dictionary is not modified, as `self.data.keys()` is lazily generated,
at least in Python 3.

Unfortunately, as we intend to change the dictionary with the `--purge`
option, we get a runtime exception when iterating the loop.

This commit fixes it by making the generation of the list of keys occur only
once, so that the dictionary itself can be modified in the body of the loop.

Tested with both Python 2.7 and Python 3.3.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
Merge pull request #202 from rbrito/master

Use non-lazy enumeration for removal of dictionary keys.