[英]How to create a list from a for-loop
I am trying to create a list of numbers from a function and a for-loop. 我试图从函数和for循环中创建数字列表。 Here is a copy of my code:
这是我的代码的副本:
Rh = 1096776000000
print "What is your value for 'n'?"
n = float(raw_input(">"))
m = range(int(n+1), int(n+21))
def wavelength(a,b):
list = [((1 / (Rh * ((1 / (a**2)) - (1 / (float(x)**2))))) * 10 ** 14)
for x in b]
return list
for elements in wavelength(n,m):
print "%.3f" % elements, 'nm'
This will print out what I want, but I need to take all of the data points and put them into a list. 这将打印出我想要的内容,但是我需要获取所有数据点并将它们放入列表中。 Any ideas?
有任何想法吗?
I guess you're in need of something like this: 我想您需要这样的东西:
l = [] # An empty list
for elements in wavelength(n,m):
l.append("%.3f" % elements, 'nm') # Adding rounded values to the list
print l # Print the full list
results = ["%.3f nm" % elements for elements in wavelength(n,m)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.