'dict' object has no attribute 'has_key'

后端 未结 6 983
太阳男子
太阳男子 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:08

    I think it is considered "more pythonic" to just use in when determining if a key already exists, as in

    if start not in graph:
        return None
    

提交回复
热议问题