我有以下变量:
InputNumber
(用户定义从1到6)
nameofstate
(两个名字的列表,我们称它们为X和Y)
list[state][protein][counts][x]
list[state][protein][counts][y]
,其中x和y是等于InputNumber长度的列表
那么InputNumber = 3
list[state][protein][counts][x] = [a,b,c]
list[state][protein][counts][y] = [r,s,t]
其中InputNumber = 4
我想为这些计数创建新列,但我无法确定如何生成动态列标题:
Name X1 X2 X3 Y1 Y2 Y3 Name X1 X2 X3 X4 Y1 Y2 Y3 Y4
Name a b c r s t Name a b c d r s t u
下面是标题的代码:
listheaders = [str(nameofstate[0]) + str(x + 1) for x in range(0, InputNumber), str(nameofstate[1]) + str(x + 1) for x in range(0, InputNumber)]
with open("PATH and NAME" + ".csv", 'w') as myfile:
wr = csv.writer(myfile, delimiter=',', lineterminator='\n')
wr.writerow(["Name", (i for i in listheaders[0]), (e for e in listheaders[1]])
for name in anotherlist:
perform the same iterative code
我的问题是生成器表达式-我无法完全理解如何告诉它将listheaders
中的条目解包。在
我不确定我是否了解你问题中发生的所有事情,但似乎你在listheaders中做得太多了。如果我理解正确,你想用一个helper函数来构造
后来。。。在
^{pr2}$相关问题 更多 >
编程相关推荐