I have this code
list = ['a','b','c']
if 'b' in list:
return "found it"
return "not found"
Now, how does this work? Does it traverse the whole list comparing the element? Does it use some kind of hash function?
Also, is it the same for this code?
list.index('b')
inuses the method__contains__. Each container type implements it differently. For a list, it uses linear search. For a dict, it uses a hash lookup.