tuples, index method, Python's design

Terry Reedy tjreedy at udel.edu
Wed Apr 11 02:48:21 CEST 2007


"BJörn Lindqvist" <bjourne at gmail.com> wrote in message 
news:740c3aec0704100824m132c45fbi5c4c3ec0c0fa3a67 at mail.gmail.com...
On 4/10/07, Steve Holden <steve at holdenweb.com> wrote:
> One might perversely allow extension to lists and tuples to allow
>
>    [3, 4] in [1, 2, 3, 4, 5, 6]
>
> to succeed, but that's forcing the use case beyond normal limits.

I'd love to have that! There are at least one million use cases for
finding a sequence in a sequence and implementing it yourself is
non-trivial. Plus then both list and tuple's index methods would work
*exactly* like string's. It would be easier to document and more
useful. A big win.

=======================
It would be ambiguous: [3,4] in [[1,2], [3,4], [5,6]] is True now.

Strings are special in that s[i] can only be a (sub)string of length 1.
'b' in 'abc' is True.  This makes looking for longer substrings easy.

However, [2] in [1,2,3] is False.  IE, list[i] is not normally a list.  So 
looking for sublists is different from looking for items.

Terry Jan Reedy






More information about the Python-list mailing list