[英]python: a shorter way to append values
results_histogram_total=list(numpy.histogram(freq,bins=numpy.arange(0,6.1,.1))[0])
sum_total=sum(results_histogram_total)
big_set=[]
for i in results_histogram_total:
big_set.append(100*(i/sum_total)
is there a shorter way i can write the for loop to append the values? 有没有更短的方法我可以编写for循环来附加值?
For appending , replace the loop with: 要进行追加 ,请将循环替换为:
big_set.extend(100.0 * i / sum_total for i in results_histogram_total)
however, it's best to replace all the last three lines with just: 但是,最好用以下方法替换所有最后三行:
big_set = [100.0 * i / sum_total for i in results_histogram_total]
Also, I would advise to not call a list "something set " -- it's very confusing disinformation. 此外,我建议不要将列表称为“ 设置 ” - 这是非常令人困惑的虚假信息。 But, this is just a bit of naming style advice;-).
但是,这只是一些命名风格的建议;-)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.