I have asked a similar question like this before but I am going to try again because I have some more questions.
I have two csv files that have 3 columns.
Name Product Amount:
I want to get the differences between the two files. I can do this if the two files are in the same order of name and product. This will give me the differences of amount which is what I am looking for.
I am needing to have something that will take to list and compare the two and show differences if not in same order.
I have tried:
import csv
import difflib
file1 = open('file1','rb').read().splitlines()
file2 = open('file1','rb').read().splitlines()
for diff in difflib.ndiff(file1, file2):
print(diff)
But if any thing is out of order no good. Is there a way I can group each “name product amount” and compare to file 2 where I have grouped each “name product amount”, and if there is a difference between file 1 and file 2 show that.
You can sort the lines using the python builtin function
sorted(alist)or sort them inplace, usingalist.sort().Also, you can use the UNIX command
sorton the files before you open them in python. That way you can be sure they are both in order.