Doesn’t really need a video, but I forgot that I stumbled into this oddity of Python2 and the getitem operator.
Someone please explain this one. I’m going crazy.
edit: BTW - same behaviour on python3 (3.4.4).
For those that can’t stand video for reading code, the code in question is:
def __getitem__(self, item):
a = A()
if "A" in a:
A few things to remember:
x.__getitem__(y) <==> x[y]
With that in mind, remember that "a" in x is roughly equivalent to:
"a" in x
i = 0
if x[i] == "a":
i += 1
The original A implementation never bothers to validate the position of getitem