Efficient way to remove keys with empty strings from a dict

前端 未结 17 1200

I have a dict and would like to remove all the keys for which there are empty value strings.

metadata = {u\'Composite:PreviewImage\': u\'(Binary data 101973          


        
17条回答
  •  离开以前
    2020-11-27 13:42

    BrenBarn's solution is ideal (and pythonic, I might add). Here is another (fp) solution, however:

    from operator import itemgetter
    dict(filter(itemgetter(1), metadata.items()))
    

提交回复
热议问题