I’m trying to be a good pythonista and use list comprehensions where possible…
Why doesn’t this work?
[del my_dict[r] for r in to_remove]
The goal is to remove the entries in the list to_remove from my dict object my_dict
This:
for r in to_remove:
del my_dict[r]
works fine but I am trying to do it with list comprehensions
You shouldn’t be using a list comprehensions for side effects, it’s not pythonic.
A simple for loop should be used instead.