Find and Replace Simplification
John Gordon
gordon at panix.com
Fri Jul 19 10:28:41 EDT 2013
In <mailman.4865.1374240179.3114.python-list at python.org> Devyn Collier Johnson <devyncjohnson at gmail.com> writes:
> 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')
If your actual use-case is this simple, you might want to use one of the
built-in string functions such as strip() or translate().
--
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list
mailing list