我是 Python 新手,遇到了一堆问题,我需要一些帮助。我有一个 python 函数需要解析一些带有 0 和 1 的简单值。
111000111
111000111
101111111
101100001
111111111
我需要用 2D 数组存储每个 0,以便以后可以引用这些位置。但是我的索引超出范围,我做错了什么以及如何解决?
这是python代码:
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;