I need to compare 2 CSV files and I am trying to use the @Martijn Pieters solution at Python: Comparing two CSV files and searching for similar items but I am running into an error:
IndexError: list index out of range
Here is the code I am using,
import csv
with open('filename.csv', 'rb') as a:
indices = dict((r[2], i) for i, r in enumerate(csv.reader(a)))
print indices
filename.csv has 10 columns and 2000 rows. I want to index column 3 that has hostnames and then match with hostnames in other .csv file
type,id,hostname,os,,,,
phy,123,server1,rhel5,,,,
vir,234,server2,rhel6,,,,
I am not sure why I am getting IndexError. Please help to fix the problem.