Nick Dumas wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[1,2] in [1,2,3] checks to see if the list [1,2] is an item in [1,2,3].
Because the list [1,2,3] only contains the integers 1,2,3, the code
returns a False. Try "[1,2] in [[1,2],[2,3]]"

The inconsistency goes deeper than that. For instance, the type of a value returned by the indexing operation:

  Indexing a string returns a string (of length 1 of course),
  while indexing a list does not (necessarily) return a list.

Conclusion: They are different types supporting different operations. Given all the obvious differences (mutability, sorting and other methods, types of individual elements), I'd say there are more differences than similarities, even though, as sequences, they both support a small subset of similar operations.

Gary Herron




David C. Ullrich wrote:
Luckily I tried it before saying no, that's
not how "in" works:

'ab' in 'abc'
True
[1,2] in [1,2,3]
False

Is there a reason for the inconsistency? I would
have thought "in" would check for elements of a
sequence, regardless of what sort of sequence it was...

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhyiwEACgkQLMI5fndAv9jbiwCeKMXrAclILJMPro5VuSRgdkvB
cGkAn1igcjFWRQJSwEDOxpk3spzceZGa
=iq8L
-----END PGP SIGNATURE-----
--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to