list = [['a', (1,1)], ['a', (1,2)], ['a', (1,4)], ['a', (1,5)]]
for i in list:
print "the i is ", i
print i[0] # 'a'
print i[1] # (1, 1)
n = 'a'
v = (1,1)
#n = re.search(r'[a-z]', i[0])
#v = (v[0], (v[1] + 1))
print "just", i[1]
print "trying ", v
for j in i:
if (j[0] != n):
v = (1, 1)
n = i[0]
if (i[1] != v):
print v
raise ValueError, '[%s, %s] is missing' %(i[0], (i[1][0], i[1][1]-1))
v = (v[0], (v[1] + 1))
在第一次迭代之后,该值似乎没有改变,即它保持为(1,1)
,但是我可以看到需要做什么才能报告列表中的缺失项,即在此示例列表中它是['a', (1, 3)]
。通常,代码以['a', (1,1)]
检测其在列表中的缺失开始,因此它按顺序跟随每个项目