数学建模例题2.42 遍历文件data2_2.txt中的所有行,统计每一行中字符的个数

`with open('data2_2.txt') as fp:
L1=[]; L2=[];
for line in fp:
L1.append(len(line))
L2.append(len(line.strip())) #去掉换行符
data = [str(num)+'\t' for num in L2] #转换为字符串
print(L1); print(L2)
with open('data2_42.txt', 'w') as fp2:
fp2.writelines(data)

print("学号:3005")`

posted on 2024-10-28 12:08  VVV1  阅读(11)  评论(0)    收藏  举报