【发布时间】:2013-06-28 15:56:07
【问题描述】:
我有一个包含内容的 foo.txt 文件
'w3ll' 'i' '4m' 'n0t' '4sed' 't0'
'it'
我正在尝试提取其中包含 2 个字符的所有单词。我的意思是,输出文件应该只有
4m
t0
it
我尝试的是,
with open("foo.txt" , 'r') as foo:
listme = foo.read()
string = listme.strip().split("'")
我想这将用 ' 符号分割字符串。 如何仅选择那些字符数等于 2 的撇号中的那些字符串?
【问题讨论】:
标签: python string file python-2.7 extract