本帖最后由 aloha20200628 于 2024-8-26 14:10 编辑
回复 1# 占卜家 - import re
- for line in open(r'C:\Users\14232\Downloads\topo.txt', 'r', -1):
- if line:=line.strip():
- nl = re.split(':| ', line, re.M)
- print(' '.join(nl[1::2]))
复制代码
python 3.8+开始支持海象运算符 :=
若是较低版本可用以下代码
- import re
- for line in open(r'C:\Users\14232\Downloads\topo.txt', 'r', -1):
- line = line.strip()
- if line:
- nl = re.split(':| ', line, re.M)
- print(' '.join(nl[1::2]))
复制代码
|