def shuffle(self, x, random=None, int=int):
"""x, random=random.random -> shuffle list x in place; return None.
Optional arg random is a 0-argument function returning a random
float in [0.0, 1.0); by default, the standard random.random.
"""
randbelow = self._randbelow
for i in reversed(range(1, len(x))):
# pick an element in x[:i+1] with which to exchange x[i]
j = randbelow(i+1) if random is None else int(random() * (i+1))
x[i], x[j] = x[j], x[i]
Run Code Online (Sandbox Code Playgroud)
When I run the shuffle
function it raises the following …
我在下面有一个词典:
colors = {
"blue" : "5",
"red" : "6",
"yellow" : "8",
}
Run Code Online (Sandbox Code Playgroud)
如何索引字典中的第一个条目?
colors[0]
将返回一个KeyError
明显的原因.
我有一个已支付的价值清单,并希望显示已支付的总金额.我使用Aggregation和Sum来一起计算值.问题是,我只想要打印出总值,但是聚合打印出:( {'amount__sum': 480.0}
480.0是总增加值.
在我看来,我有:
from django.db.models import Sum
total_paid = Payment.objects.all.aggregate(Sum('amount'))
Run Code Online (Sandbox Code Playgroud)
为了显示页面上的值,我有一个mako模板,其中包含以下内容:
<p><strong>Total Paid:</strong> ${total_paid}</p>
Run Code Online (Sandbox Code Playgroud)
如何让它显示480.0
而不是{'amount__sum': 480.0}
?
best_params_train = dict(optimizer=optimizers[0], learning_rate=learning_rates[0],
cnn_train_type=cnn_train_types[0],
cnn_arch=cnns_arch.values()[0],
dropout=dropouts[0])
Run Code Online (Sandbox Code Playgroud)
它在 cnn_arch=cnns_arch.values()[0] 处给出错误 TypeError: 'dict_values' object is not subscriptable。我尝试转换为列表但没有成功。如何将上面的 dict(....) 转换为列表
exp_params_train = dict(optimizer=optimizers[1:], learning_rate=learning_rates[1:],
cnn_train_type=cnn_train_types[1:], dropout=dropouts[1:],
cnn_arch=cnns_arch.values())
Run Code Online (Sandbox Code Playgroud)