# 分割字符串成为一个列表 # oj 题的读入 a, b, c = input().split() # 按逗号分割 s = 'a,b,c' ls = s.split(',') # 反向合成 s # 注意 p.join 是以 p 为分隔符, 把 ls 这样一个字符串列表拼接起来 new_s = ','.join(ls)
withopen(filename, 'r', encoding='utf-8') as f: lines = f.readlines()
new_lines = [] count = 0 for i, line inenumerate(lines): if line or (i > 0and lines[i-1]): if'。'notin line: new_lines.append('') new_lines.append(line) new_lines.append('') count += 1 else: new_lines.append(line)
lines = [line.rstrip() for line in new_lines]
count += len(new_lines) - len(lines)
while lines andnot lines[-1]: lines.pop() count += 1
trimmed_lines = [] for i, line inenumerate(lines): if line or (i > 0and lines[i-1]): trimmed_lines.append(line) count += 1
withopen(filename, 'w', encoding='utf-8') as f: f.write('\n'.join(trimmed_lines)) f.write('\n')
print(f"Modified {count} lines in file {filename}.")