alex1997 alex1997 - 1 year ago 117
Python Question

How to remove hyphen from compound words?

If i have a string:

txt = "Good-bye my friend"

I want it to be like this:

txt = "Good bye my friend"

What should i do?

Answer Source


string.replace(s, old, new[, maxreplace]) Return a copy of string s with all occurrences of substring old replaced by new. If the optional argument maxreplace is given, the first maxreplace occurrences are replaced.

So replace your hyphen with a space:

txt = txt.replace('-', ' ')

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download