【发布时间】:2019-04-23 12:35:18
【问题描述】:
我有一个 *.xvg 文件和 3 个不同的组,我想将它们存储在 3 个列表中。前 2 组具有共同特征,因此可以使用 line.startswith() 命令。但是,第三个列表要长得多并且会有所不同,所以我想从不在 list1 和 list2 中的值创建一个列表。
我试过 not in not in,但我猜想读取文件出了点问题,因为它没有存储任何值。
for line in open(name):
if line.startswith(' 4755') or line.startswith(' 4756') or line.startswith(' 4759') or line.startswith(' 4760'):
l = line.split()
arm1.append(float(l[1]))
sum1= sum(arm1[0:len(arm1)])
elif line.startswith(' 4768') or line.startswith(' 4769') or line.startswith(' 4770') or line.startswith(' 4771') or line.startswith(' 4772') or line.startswith(' 4773') or line.startswith(' 4783') :
l = line.split()
arm2.append(float(l[1]))
sum2= sum(arm2[0:len(arm2)])
if line not in [arm1] or [arm2]:
l = line.split()
arm3.append(float(l[1]))
sum3= sum(arm3[0:len(arm3)])
【问题讨论】:
标签: python python-3.x list if-statement