If I have a dictionary, and I want to remove the entries in which the value is an empty list []
how would I go about doing that?
I tried:
for x in dict2.keys():
if dict2[x] == []:
dict2.keys().remove(x)
but that didn't work.
Newer versions of python support dict comprehensions:
dic = {i:j for i,j in dic.items() if j != []}
These are much more readable than filter or for loops
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With