Python: Checking if a 'Dictionary' is empty doesn't seem to work

前端 未结 8 538
旧巷少年郎
旧巷少年郎 2020-12-02 04:27

I am trying to check if a dictionary is empty but it doesn\'t behave properly. It just skips it and displays ONLINE without anything except of display the m

相关标签:
8条回答
  • test_dict = {}
    if not test_dict.keys():
        print "Dict is Empty"
    
    0 讨论(0)
  • 2020-12-02 04:57

    use 'any'

    dict = {}
    
    if any(dict) :
    
         # true
         # dictionary is not empty 
    
    else :
    
         # false 
         # dictionary is empty
    
    0 讨论(0)
提交回复
热议问题