How to remove all keys with value 0 from a dictionary in Python

1 Answer

0 votes
dic = {'a':0, 'b':0, 'c':1, 'd':3, 'e':0, 'f':4}

dic = {key:val for key, val in dic.items() if val != 0}

print(dic)
  
      
      
  
'''
run:
  
{'c': 1, 'd': 3, 'f': 4}

'''
 

 



answered Feb 24, 2023 by avibootz
...