<分区>
这是我的代码:
def generate_float_population(count, size):
return [generate_float_individual(size) for item in range(count)]
我的 IDE 说,没有使用变量“item”。我想知道是否有更优雅的方法来做到这一点。
<分区>
这是我的代码:
def generate_float_population(count, size):
return [generate_float_individual(size) for item in range(count)]
我的 IDE 说,没有使用变量“item”。我想知道是否有更优雅的方法来做到这一点。
最佳答案
如果实际上每次都必须调用该函数,那么这将起作用
def generate_float_population(count, size)
return map(generate_float_individual, [size] * count)
但是如果每次都产生相同的值那么
def generate_float_population(count, size)
return [generate_float_individual(size)] * count
关于python - 在不创建不会使用的变量的情况下在 python 中循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36107452/