4 ms·
Not claiming to be the fastest, but here are two Python solutions suggested by Dave Beazley [0], plus one I extended using compiled regular expressions: #
by hcrisp 10y ago
Not claiming to be the fastest, but here are two Python solutions suggested by Dave Beazley [0], plus one I extended using compiled regular expressions:
# string replacement
s = ' hello world \n'
s.replace(' ', '')
# 'helloworld'
# regular expression
import re
re.sub('\s+', '', s)
# 'helloworld'
# compiled regular expression
pat = re.compile('\s+')
pat.sub('', s)
# 'helloworld'
[0] https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiDwpPQytHRAhVJWCwKHSTmD5wQFggaMAA&url=https%3A%2F%2Fwww.safaribooksonline.com%2Flibrary%2Fview%2Fpython-cookbook-3rd%2F9781449357337%2Fch02s11.html&usg=AFQjCNEZqL6SV76UmE4ojyJ5poOgeCexEQ&sig2=I9kGVDVg5DyLxZ3pCJ1FIw&bvm=bv.144224172,d.bGg https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&c...