python 创建数组
stop = [2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000, 3400.0, 8840.0,2000,2000,2000, 4600.0,2000, 4600.0, 10580.0, 10580.0,2000, 7600.0, 58520.0,2000, 3600.0,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000]
两个list,创建新list包含36个对象,每个对象的取值范围是range(start[i],stop[i],100)
marix=[for i in range(0,36):
x for x in range(start[i],stop[i],100)]
print (marix) 展开
start = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
110.00000000000001, 198.0, 198, 396, 100, 150.0,
100, 150.0, 225.0, 225.0, 100, 260.0, 1326.0, 100, 120.0, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100]
stop = [2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
3400.0, 8840.0, 2000, 2000, 2000, 4600.0, 2000, 4600.0,
10580.0, 10580.0, 2000, 7600.0, 58520.0, 2000, 3600.0, 2000, 2000,
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000]
print(len(start))
print(len(stop))
marix = [x for i in range(0, 37)
for x in range(int(start[i]), int(stop[i]), 100)]
print(marix)
列表解析语法:
[expression for iter_val in iterable]
[expression for iter_val in iterable if cond_expr]
你的start和stop里除了int还含有float类型,解析的时候用int()转换
参考资料: