Corrected several usage of keys() for Python 3

Under Python2 dict.keys() returns a list, under Python 3 it returns an
iterator. Some places assumed that if they called keys() then it was
safe to modify the dict in a loop. Corrected this by calling list().

Change-Id: I7638263f288dd20590bd751d09194a919b921545
py33: dict.keys() is not a list in python3

Cast the dict.keys() to list when comparing its value with list.

Closes-Bug: #1228993

Change-Id: I59d13258935de3e9286845f857eaa602a5b690fb
Merge "py33: dict.keys() is not a list in python3"
Merge "Corrected several usage of keys() for Python 3"