Programming/Python newb here looking for some help with arrays. I am trying to write a parsing program that takes a comma delimited csv file, compares entries, and outputs the comparisons in a particular format.
The csv file has two columns. Col  contains article identifiers, col contains assigned keywords. It looks something like this:
I wrote the following code, which compares the entry in row i, col 0, with the entry in row i+1, col 0. If the article id's are equal, then I need to print out the two keywords on the same line.
import csv edgelist1= #initialize the first edge list listmax = 0 #use to calculate the largest index value of the array #import the article_kwd file reader = csv.reader(open('C:/scientometric/kw.csv', 'r'), delimiter = ',', quoting=csv.QUOTE_NONE) for row in reader: edgelist1.append (row) listmax = listmax+1 #use to determine whether or not two keywords are connected #by checking to see if they are both assigned to the same article for i in range (0,listmax): nextrow=i+1 while edgelist1[i]==edgelist1[nextrow]: print (edgelist1[i],edgelist1[nextrow]) nextrow=nextrow+1
This works really well. It produces an output like this:
ANTIMICROBIAL RESISTANCE CARRIAGE
ANTIMICROBIAL RESISTANCE EXPERIENCE
ANTIMICROBIAL RESISTANCE INFECTION
ANTIMICROBIAL RESISTANCE PNEUMOCOCCAL-INTERVENTION-PROJECT
ANTIMICROBIAL RESISTANCE SEROTYPES
ANTIMICROBIAL RESISTANCE SPAIN
ANTIMICROBIAL RESISTANCE STRAINS
However, I need to take this one step further. I need to replace the keywords with their key values. The output needs to look something like this:
What I have been trying to do is write the output into an interim array. However, no matter what I try, I keep getting an error message that the list index is out of range.
Any advice on how to get past this?