相关疑难解决方法(0)

删除字符串中多个空格的简单方法?

假设这是字符串:

The   fox jumped   over    the log.
Run Code Online (Sandbox Code Playgroud)

这将导致:

The fox jumped over the log.
Run Code Online (Sandbox Code Playgroud)

什么是最简单的1-2衬垫可以​​做到这一点?没有分裂并进入列表......

python regex string

338
推荐指数
14
解决办法
30万
查看次数

在Python列表中查找并替换字符串值

我有这个清单:

words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']
Run Code Online (Sandbox Code Playgroud)

我想要的是取代[br]一些类似的奇妙价值<br />,从而得到一个新的清单:

words = ['how', 'much', 'is<br />', 'the', 'fish<br />', 'no', 'really']
Run Code Online (Sandbox Code Playgroud)

python string list

134
推荐指数
5
解决办法
34万
查看次数

删除文件输出中的换行符/返回载体

我有一个单词列表,其中包含用于分隔每个新字母的返回.有没有办法在Python中使用文件I/O以编程方式删除每个返回?

编辑:我知道如何操纵字符串来删除返回.我想物理编辑该文件,以便删除这些返回.

我正在寻找这样的东西:

wfile = open("wordlist.txt", "r+")           
for line in wfile:
    if len(line) == 0:
        # note, the following is not real... this is what I'm aiming to achieve.
        wfile.delete(line)
Run Code Online (Sandbox Code Playgroud)

python io file

10
推荐指数
2
解决办法
7万
查看次数

标签 统计

python ×3

string ×2

file ×1

io ×1

list ×1

regex ×1