Простое наивное решение будет:
s = 'do not-remove this-hyphen but remove-all of these-hyphens'
words_to_keep = {'not-remove', 'this-hyphen'}
new_s = []
for word in s.split():
if word not in words_to_keep:
word = word.replace('-', ' ')
new_s.append(word)
print(' '.join(new_s)) # do not-remove this-hyphen but remove all of these hyphens
Еще один подход с картой:
def unhyphen_word(word):
return word.replace('-', ' ') if word not in words_to_keep else word
print(' '.join(map(unhyphen_word, s.split())))
или составление списка:
print(' '.join([unhyphen_word(word) for word in s.split()]))