def trans_list(l1): info = [] current = [] count = 0 for i in l1: if not i: count += 1 elif count: current.append(count) count = 0 if count: current.append(count) print(current) index = 0 for i in current: s = (index, index + i + 1) index += i + 1 info.append(s) return info def dif(*lines): info = [[]]*len(lines) # assert len(info) > 1 num = len(lines[0]) for i in range(num): print('i:', i, 'info:', info) v = lines[0][i] sm = True for index, j in enumerate(lines[1:]): if len(j) > i: if j[i] != v: sm = False print(index + 1) info[index + 1].append(False)
print(info) else: info[index + 1].append(True)
print(info) info[0].append(sm)
print(info) print(info) # 转换info return [trans_list(i) for i in info] print(dif('qwes', 'wwerr'))
运行这段代码,发现info内的两个子列表不知道为什么同时被增加了?????????
明明只有“info[1].append(False)”的!
标签:info,index,Python,count,current,犯错,print,当着,append From: https://www.cnblogs.com/roundfish/p/17013020.html