import csv
def compareList(l1,l2):
if(len(l1)==len(l2) and len(l1)==sum([1 for i,j in zip(l1,l2) if i==j])):
return "Equal"
else:
return "Non equal"
file1 = "C:/Users/Sarvesh/Downloads/a.csv"
file2 = "C:/Users/Sarvesh/Downloads/b.csv"
with open(file1, 'r') as csv1, open(file2, 'r') as csv2: # Import CSV files
import1 = csv1.readlines()
import2 = csv2.readlines()
# creating an object of csv reader
# with the delimiter as ,
csv_reader = csv.reader(import1, delimiter='|')
# list to store the names of columns
list_of_column_name1 = []
# loop to iterate through the rows of csv
for row in csv_reader:
# adding the first row
list_of_column_name1.append(row)
# breaking the loop after the
# first iteration itself
break
csv_reader = csv.reader(import2, delimiter='|')
# list to store the names of columns
list_of_column_name2 = []
# loop to iterate through the rows of csv
for row in csv_reader:
# adding the first row
list_of_column_name2.append(row)
# breaking the loop after the
# first iteration itself
break
# printing the result
print("1List of column names : ", list_of_column_name1[0])
print("2List of column names : ", list_of_column_name2[0])
print("First comparison",compareList(list_of_column_name1,list_of_column_name2))