Removing punctuation/symbols from a list with Python except periods, commas
<p>In Python, I need to remove almost all punctuation from a list but save periods and commas. Should I create a function to do this or a variable? Basically I want to delete all symbols except letters (I've already converted uppercase letters to lowercase) and periods and commas (and maybe apostrophes). </p>

<pre><code>#Clean tokens up (remove symbols except ',' and '.')

def depunctuate()
   clean_tokens = []

   for i in lc_tokens:
       if (i not in [a-z.,])
       ...
</code></pre>

<pre><code>import string

# Create a set of all allowed characters.
# {...} is the syntax for a set literal in Python.
allowed = {",", "."}.union(string.ascii_lowercase)

# This is our starting string.
lc_tokens = 'hello, "world!"'

# Now we use list comprehension to only allow letters in our allowed set.
# The result of list comprehension is a list, so we use "".join(...) to
# turn it back into a string.
filtered = "".join([letter for letter in lc_tokens if letter in allowed])

# Our final result has everything but lowercase letters, commas, and
# periods removed.
assert filtered == "hello,world"
</code></pre>

python normalization