[英]how to make this a list comprehension
How do I write this as a list comprehension? 如何将其写为列表理解?
for i in range(len(genes)):
if compareGenes(genes[i], target) > count:
best = genes[i]
count = compareGenes(genes[i], target)
max
with a generator comprehension would be a nice way to go. 用生成器理解
max
可以是一个不错的方法。
count, best = max((compareGenes(k, target), k) for k in genes)
Alternately, use a key
argument to max
: 或者,对
max
使用key
参数:
best = max(genes, key=lambda k: compareGenes(k, target))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.