Translate Function

Hello!

I am trying to clean the data and remove all punctuation from a string.
I use the function translate. but it doesn’t work.
Should I import special library to work with this function?

def cleanup(stringo):
    stri =stringo.lower().replace('/W','')
    zap = '.,;:[email protected]#$^&*)(?><:\/'
    symbols = str.maketrans('.,;:[email protected]#$^&*)(?><:\/',' '*len(zap))
    stri.translate(symbols)
    stri.replace(':','')
    return stri

Thanks.

.translate returns a new string.
.replace returns a new string.

What you want is

return stri.translate(symbols).replace(":", " ")
2 Likes

Thank you, I will try…

Yes, It works. ) :wave: :wave: :wave: :wave:

1 Like

We have a solved feature that allows you the ability to mark something as the “correct” answer, which helps future students with the same question quickly find the solution they’re looking for.

Here’s an article on how to mark posts as solved - I don’t want to do this for you until I know that solution/explanation works.

Thanks. I pushed on three dots near the Reply button under the past. Am I done everything correctly?