Flatten... or How to determine sequenceability?

Alex Martelli aleaxit at yahoo.com
Sat May 26 03:18:24 EDT 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.990826839.12032.python-list at python.org...
    ...
> This is already available, via the operator.isSequenceType() function
(which

Ooops (and thanks to /F for the same remark, too).  I wonder if and
ever I'll ever know by heart everything that's in the standard lib!-)

    [snippage]

> but then that's because people come to Python expecting stuff like "is a
> sequence" to be crisp concepts.  But they aren't in Python, and after
> introducing iterable objects, they're even fuzzier.
>
> but-fuzzy-in-a-warm-and-loving-way-ly y'rs  - tim

OK, "is-a sequence" is a typical Korzybskian "is of identity", thus
I guess it's quite reasonable to have it be a fuzzy concept.

But a need for something sharper does arise.  "Behaves like a
sequence" (or "can adapt to sequence protocol", or "respects
sequence interface").  A dictionary "behaves" like a sequence
in a very partial way: if I do a "for k in dict" and just process
k I've lost substantial information (all of the values) and have
warmly and lovingly been fed non-information (an arbitrary
ordering of the keys).

I believe the normal concept of sequence does include ordering
as being significant, and no information loss -- list, tuple,
array.array, UserList -- no doubt files and (special cases that
it would be nice to have another sharp test for:-) strings and
unicode-strings, too.

With distinctions within the overall category of sequences, sure
(mutable vs not, with predefined length vs without).  But it seems
to me that if either or both of the interfaces and protocol-adaptation
PEPs passed, 'such-and-such-a-sequence's would be useful
interfaces/protocols to have.


Alex






More information about the Python-list mailing list