One liner to determine if dictionary values are all empty lists or not

前端 未结 6 926
-上瘾入骨i
-上瘾入骨i 2021-01-01 22:24

I have a dict as follows:

someDict = {\'a\':[], \'b\':[]}

I want to determine if this dictionary has any values which are not empty lists.

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 23:02

    try this

     all([d[i] == [] for i in d])
    

    edit: oops, i think i got you backwards. lets deMorgan that

    any([d[i] != [] for i in d])
    

    this second way has the short-circuit advantage on the first anyhow

提交回复
热议问题