Is there a simple way to remove multiple spaces in a string?

后端 未结 29 2157
星月不相逢
星月不相逢 2020-11-22 08:17

Suppose this string:

The   fox jumped   over    the log.

Turning into:



        
29条回答
  •  情书的邮戳
    2020-11-22 09:01

    This does and will do: :)

    # python... 3.x
    import operator
    ...
    # line: line of text
    return " ".join(filter(lambda a: operator.is_not(a, ""), line.strip().split(" ")))
    

提交回复
热议问题