How to replace all spaces by underscores and remove all the parentheses without using replace() function?
<p>Here is what I did. I know this is definitely wrong. I'd like to know how to make this one work? Thx!</p>

<pre><code>import re
def demicrosoft (fn):

"""Clean up a file name.

Remove all parentheses and replace all spaces by underscores.

Params: fn (string): 
Returns: (string) clean version of fn
"""

fn = re.sub('[()]', '', fn)
for ch in ['']:
    fn = fn.translate(ch, "_")
return fn

print(demicrosoft('Quercus stellata (26).jpg'))
</code></pre>

<pre><code>newString = re.sub("([\s\(\)])",lambda m:"_" if b.group(0) not in "()" else "",targetString)
</code></pre>

<p>im guessing its for a performance reasons and they want <code>O(N)</code>  the generator expression should work ... here is an <code>re</code> solution</p>

python replace removeall