- 帖子
- 36
- 精华
- 0
- 积分
- 127
- 阅读权限
- 20
- 注册时间
- 2016-10-18
- 最后登录
- 2016-11-23
|
本帖最后由 Tony 于 2016-11-5 09:30 编辑
crossin先生 发表于 2016-11-4 14:18
输出
['roads', 'must', 'a', 'man', 'walk', 'they', 'call', 'him', 'a', 'man', 'a', 'is', 'blowing' ...
我是这样写的:
- import re
- PATH = r'C:\Users\Tony\Desktop\Demo\demo.txt'
- s= open(PATH)
- file_read = s.read()
- words = re.findall(r'(?<=\s)[A-z]+(?=\s|$)|^[A-z]+', file_read)
- print words
复制代码 结果:- ['Ho', 'roads', 'must', 'a', 'man', 'walk', 'they', 'call', 'him', 'a', 'man', 'a', 'is', 'blowing', 'in', 'the', 'wind', 'The', 'answer', 'is', 'blow', 'in', 'the']
复制代码 demo.txt 的内容是这些:
Ho454w m545any roads must a man walk downBef434ore they call him a man
H767ow m767any s767eas m676ust a wh453ite do4543ve sai45l
Be56fore s565he sle3434eps i343n th434e san453d
Ho343w man565y tim5767es m767ust t78he cann564on ba45lls f656ly
Be686fore the7876y're f787orever ba7878nned
T7567he an75675swer m76y fr656iend is blowing in the wind
The answer is blow .ing in the wi1n3d
|
|