mardi 23 avril 2019

Getting values from a file that are not stored in two other lists

I have a *.xvg file and 3 different groups I want to store in 3 lists. First 2 groups have common traits so it is okay to use line.startswith() command. However, 3rd list is much longer and will differ, so I want to create a list from values that are not in list1 nor list2.

I tried not in not in but I guess something goes wrong with reading the file since it stores no value.

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)])

Aucun commentaire:

Enregistrer un commentaire