[Tutor] how to remove the coming duplication

lina lina.lastname at gmail.com
Thu Nov 10 09:26:24 CET 2011


<snip>

Thanks for all, I found the problems I faced is more tricky than the
simple list I gave.

Here the list is: a row of numbers, not one number,

such as print a_list[1] is:

1
1
9
7
7
9
9
9

print(a_list) is:

617
617
790
571
571
790
790
790

I attached the codes written based on the suggestions all you have
given, and also attached the to-be-handled file in the following link:

#!/usr/bin/python3

import os.path

INFILEEXT=".out"
OUTFILEEXT=".bri"

atoms=[]

def fetchonefiledata(infilename):
        for line in open(infilename,"r"):
                parts=line.strip().split()
                atoms=parts[2]
                print(atoms[0])

def remove_coming_duplications(a_list):
        for idx, element in enumerate(a_list):
                if element != a_list[idx-1]:
                        print(element)

if __name__=="__main__":
        for filename in os.listdir("."):
                base, ext = os.path.splitext(filename)
                if ext == INFILEEXT:
                        fetchonefiledata(filename)
                        remove_coming_duplications(atoms)

https://docs.google.com/open?id=0B93SVRfpVVg3MjVlODdiOWYtY2FlYy00NDIzLThjMzAtMDk0NTQ4ZTRjZjRh

Thanks with best regards,

P.S My primary interest is getting the lists from different files,
hopefully in the end find some rules between those numbers. or
pathway, such as
1 2 4 8 7 6
4 8 7 6 5 1
so it shares a feature of 4 -> 8 -> 7 -> 6.


More information about the Tutor mailing list