I'm having a hard time understanding the difference here, could some one help?
So I'm used to checking for substrings with
>>>"test" in "testing"
True
So why doesn't this work?
>>>[1, 2, 3] in [1, 2, 3, 4, 5]
False
The first case is testing for a series inside another series, so I understand why
>>>[1, 2, 3] in [[1, 2, 3], 4, 5]
True
is true, but I can't get over the fact that strings and arrays use "in" differently. Is there something for arrays that behaves more like "contains" in set theory?
Posted Nov 1, 2012, 6:58 PM UTC
inis just sugar for the.__contains__()method. Lists and strings implement that method differently. I can imagine a couple reasons for the difference, the main one being that substring matching is more common than your second example.Yeah, that makes sense, I guess my question was more about why they would change the behavior between two concepts that are almost exactly the same.