擅长:python、mysql、java
<p>实际上,我会使用列表理解,但是你的代码已经很有效了。你知道吗</p>
<pre><code>pattern = re.compile("[^A-Za-z0-9]")
cleanlist = [pattern.sub('', s) for s in dirtylist if str(s)]
</code></pre>
<p>另外,这是一个重复:<a href="https://stackoverflow.com/questions/1276764/stripping-everything-but-alphanumeric-chars-from-a-string-in-python">Stripping everything but alphanumeric chars from a string in Python</a></p>