replace PyMapping_Keys() usage by safer code (PyMapping_Keys() may return a tuple, but we try to sort it as a list afterwards)