A quick and easy way to check if all elements in a dictionary are empty strings?

I have a dictionary of N items. Their values ​​are strings, but I'm looking for an easy way to determine if they are all empty strings.

{'a': u'', 'b': u'', 'c': u''} 
+4
source share
2 answers
 not any(dict.itervalues()) 

Or:

 all(not X for X in dict.itervalues()) 

Depending on what you find more clear.

+12
source

Try the following:

 >>> d={'a':'', 'b':'', 'c':''} >>> any(map(bool, d.values())) False >>> d={'a':'', 'b':'', 'c':'oaeu'} >>> any(map(bool, d.values())) True 
+1
source

Source: https://habr.com/ru/post/1379997/


All Articles