dictview

dict.keys()[0] on Python 3

dict.keys()[0] on Python 3 Question: I have this sentence: def Ciudad(prob): numero = random.random() ciudad = prob.keys()[0] for i in prob.keys(): if(numero > prob[i]): if(prob[i] > prob[ciudad]): ciudad = i else: if(prob[i] > prob[ciudad]): ciudad = i return ciudad But when I call it this error pops: TypeError: ‘dict_keys’ object does not support indexing is …

Total answers: 3