Skip to content

Instantly share code, notes, and snippets.

@lucascoelhof
Last active January 25, 2023 04:04
Embed
What would you like to do?
How to delete a dictionary key that matches a regex (regular expression) in python
pattern = re.compile(regex)
matched_keys = {key for key, value in dic.iteritems() if pattern.match(key)}
for key in matched_keys:
dic.pop(key, None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment