How to filter a dictionary by value in Python

1 Answer

0 votes
dic = {5 : 'python', 8: 'java', 12: 'c', 19: 'c++', 18 : 'c#'}
  
filtered_dic = dict(filter(lambda element: len(element[1]) > 2, dic.items()))

 
print(filtered_dic)
  
  
  
'''
run:
  
{5: 'python', 8: 'java', 19: 'c++'}
  
'''

 



answered Jan 29, 2020 by avibootz
...