Find and Replace Simplification

Novocastrian_Nomad gregory.j.baker at gmail.com
Fri Jul 19 15:38:31 CEST 2013


On Friday, July 19, 2013 7:22:48 AM UTC-6, Devyn Collier Johnson wrote:
> I have some code that I want to simplify. I know that a for-loop would 
> 
> work well, but can I make re.sub perform all of the below tasks at once, 
> or can I write this in a way that is more efficient than using a for-loop?
> 
> DATA = re.sub(',', '', 'DATA')
> DATA = re.sub('\'', '', 'DATA')
> DATA = re.sub('(', '', 'DATA')
> DATA = re.sub(')', '', 'DATA')


Try DATA = re.sub(r'[(,\\)]', '', 'DATA')




More information about the Python-list mailing list