'dict' object has no attribute 'has_key'
has_key
was removed in Python 3. From the documentation:
- Removed
dict.has_key()
– use thein
operator instead.
Here's an example:
if start not in graph: return None
In python3, has_key(key)
is replaced by __contains__(key)
Tested in python3.7:
a = {'a':1, 'b':2, 'c':3}print(a.__contains__('a'))
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)>> Trueprint('E' in graph)>> False