Fix dependency on random order of dict.keys()