"in"consistency?
David C. Ullrich
dullrich at sprynet.com
Tue Jul 8 11:53:13 EDT 2008
In article <g4ud3d$bro$1 at aioe.org>, Mel <mwilson at the-wire.com> wrote:
> Ben Finney wrote:
>
> > "David C. Ullrich" <dullrich at sprynet.com> writes:
> >
> >> >>> 'ab' in 'abc'
> >> True
> >> >>> [1,2] in [1,2,3]
> >> False
> >
> > <URL:http://www.python.org/doc/ref/comparisons.html>
> >
> >> Is there a reason for the inconsistency?
> >
> > Probably. The special behaviour of string types was changed in Python
> > 2.3, according to that document.
>
> As it stands, you'd get
>
> [1,2] in [1,2,3] == False
>
> [1,2] in [1, [1,2], 3] == True
>
>
> This could be a good thing.
Oh, of course that's a good thing - changing "in" for lists
to give True there would be awful. I was wondering why it
_does_ work that way for strings.
Maybe the answer is "because it can" - for strings the sort
of possible problem you point out can't come up.
> Mel.
> >
--
David C. Ullrich
More information about the Python-list
mailing list