Yan Long Yan Long - 2 months ago 13
Python Question

How to remove non alphanumeric characters in a dictionary using python [Solved]

I have a dictionary like:

{...., '5':24, '/':25', 'a':26', ....}

How can I remove the punctuations and digits in order to only keep the alphanumeric characters in the dictionary?

I can do a traditional way to remove those items by indexing the key, but is there an efficient way to remove them by using regular expression?


with dictionary d:

d = {key: value for key, value in d.items() if key.isalpha()}