I have quite large amount of text which include control charachters like \n \t and \r.
I need to replace them with a simple space–> ” “. What is the fastest way to do this?
Thanks
I have quite large amount of text which include control charachters like \n \t
Share
I think the fastest way is to use
str.translate():prints
EDIT: As this once again turned into a discussion about performance, here some numbers. For long strings,
translate()is way faster than using regular expressions:That’s about a factor 40.