'dict' object has no attribute 'has_key'

后端 未结 6 981
太阳男子
太阳男子 2021-01-30 03:46

While traversing a graph in Python, a I\'m receiving this error:

\'dict\' object has no attribute \'has_key\'

Here is my code:

6条回答
  •  再見小時候
    2021-01-30 04:18

    has_key has been deprecated in Python 3.0. Alternatively you can use 'in'

    graph={'A':['B','C'],
       'B':['C','D']}
    
    print('A' in graph)
    >> True
    
    print('E' in graph)
    >> False
    

提交回复
热议问题