I\'m building a data extract using scrapy and want to normalize a raw string pulled out of an HTML document. Here\'s an example string:
Sapphire RX460 OC
Instead of using regex's for this, a more efficient solution is to use the join/split option, observe:
>>> timeit.Timer((lambda:' '.join(' Sapphire RX460 OC 2/4GB'.split()))).timeit()
0.7263979911804199
>>> def f():
return re.sub(" +", ' ', " Sapphire RX460 OC 2/4GB").split()
>>> timeit.Timer(f).timeit()
4.163465976715088