[Python] .replace() in Python not replacing punctuation with whitespace as planned [closed]

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have a text file from which I have to clean out all the punctuation and replace it with whitespace, but for words such as "leaf-shaped" (compound words with hyphen), it is not working. I don't know what I might be doing wrong.

    punc_variable = punc_variable.replace("’", " ")
    punc_variable = punc_variable.replace("‘", " ")
    punc_variable = punc_variable.replace("…", " ")
    punc_variable = punc_variable.replace("–", " ")
    punc_variable = punc_variable.replace("“", " ")
    punc_variable = punc_variable.replace("”", " ")
    punc_variable = punc_variable.replace("-", " ")
    punc_variable = punc_variable.lower()

    Continue reading...

Compartilhe esta Página