如何在python中將單詞之間的單個空格替換爲'_'?替換python中單詞之間的單個空格
例如:
輸入:
09 Web Problem Any problem has to do with the dept. web sites
12 SW Help Questions about installed SW (hotline support)
輸出:
09 Web_Problem Any_problem_has_to_do_with_the_dept._web_sites
12 SW_Help Questions_about_installed_SW_(hotline_support)
感謝!
's.replace('','_')'會是答案,但是您似乎有一個要求不要在數字上加下劃線。 – hughdbrown 2012-02-04 04:47:37
不,現在問題格式正確(文本中提到「單個空白區域」的事實),要求僅替換自身發生的空間(或空白區域)。換句話說,不要觸及多於一個尺寸的空白組。 – paxdiablo 2012-02-04 04:59:26