Skip to content Skip to sidebar Skip to footer

How To Compare Multiple Files In Python And Show All The Name Variations Associated With Ssn's

Filter/sort files to list all names variations associated with each SSN. Input File1: SSN, First Name, Last Name 333-22-9898, Tom, Tillman 556-11-7484, Mak, Burhan 333-22-9898,

Solution 1:

Answer :

f = open('out.txt', 'w')
# sample data in f1.txt (111-23-9999)
filenames = ["f1.txt", "f2.txt", "f3.txt", "f4.txt"]
files = [open(name) for name in filenames]

sets = [set(line.strip() for line in file) 
            for file in files]
common = set.union(*sets)

my_list = list(common)
my_list.sort()
print (my_list)
for file in files: file.close()


for line in my_list:
    f.write(line+'\n')
f.close()

Post a Comment for "How To Compare Multiple Files In Python And Show All The Name Variations Associated With Ssn's"