I’m new to Python and running into a heap of problems and I need some help. I have a python function that needs to parse through some simple values with 0s and 1s.
111000111
111000111
101111111
101100001
111111111
I need to store each 0s with a 2D array so the positions can be referenced later. But I’m getting a index out of range, what am I doing wrong and how to fix it?
Here’s the python code:
def storeSubset(fileName):
locale = dataParser(fileName); test = [];
subset = []; subSetCount = 0; columnCt =0;
rowList = []; columnList=[];
for rowCount in range(0, len(locale)):
# print " "; print " "
# print "Values of one row locale[row]: ", locale[rowCount];
# print "We are at row# 'row': ", rowCount;
# print "Length of row is int(len(locale[rowCount]))", int(len(locale[rowCount]));
test = locale[rowCount];
for columnCount in range (0, int(len(locale[rowCount])-1)):
rowVal = locale[rowCount][columnCount];
# print "Value of column is :", rowVal;
if (rowVal==0):
# print "columnVal = 0, the column position is ", columnCount;
subset[subSetCount].append(rowList[rowCount]);
subset[subSetCount].append(rowList[columnCount]);
subSetCount+=1;
print "The Subsets is :", subset;
return subset;
When you have
subset[subSetCount], subset is still an empty list, so the index is out of range. The same is true forrowList[rowCount]androwList[columnCount].From here, I’ll speculate a little about what you’re trying to do to help you fix it. It seems like maybe instead of
you just want
Then, after the
for columnCountloop, maybe you wantor something like that.