jeudi 6 février 2020

Compare two files - line by line using conditions in Python

Comparing line by line in two files with integers where the first file is big one. As a result will be presented result.txt file where will be only those lines that NOT contains elements from line in second files.I want to do it with sets but I cant find the proper condition.

 result = open('result.txt','w')
 with open('file1.txt','r') as fg 
 for Gline in fg:

    DDD=Gline.strip()
    GGG=set(DDD.split(' '))
    KKK=sorted(list(map(int, list(GGG))))
    with open('file2.txt','r') as fm:
        for Mline in fm:
            AAA = Mline.strip()
            BBB = set(AAA.split(' '))
            QQQ = GGG & BBB
            if BBB < GGG:        
                print(' '.join(map(str,KKK)))
                result.write(' '.join(map(str,KKK)))
                result.write("\n")
                break 
   result.close()

Aucun commentaire:

Enregistrer un commentaire