小编Men*_*ito的帖子

Python 3上的dict.keys()[0]

我有这句话:

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
Run Code Online (Sandbox Code Playgroud)

但是当我调用它时,这个错误弹出:

TypeError: 'dict_keys' object does not support indexing
Run Code Online (Sandbox Code Playgroud)

这是版本问题吗?我正在使用Python 3.3.2

python dictionary python-3.x dictview

41
推荐指数
2
解决办法
3万
查看次数

如何将y = pow(x,z)反转为x?

据我所知,没有内置函数可以直接执行此操作,所以log()?或简单的数学快捷方式,如:

z = y ** (1/x)
Run Code Online (Sandbox Code Playgroud)

X?

python math logarithm square-root pow

1
推荐指数
1
解决办法
90
查看次数

标签 统计

python ×2

dictionary ×1

dictview ×1

logarithm ×1

math ×1

pow ×1

python-3.x ×1

square-root ×1