operator module isSequenceType with builtin set produces False

MarkE mark.english at rbccm.com
Wed Dec 19 04:28:03 EST 2007


On 19 Dec, 10:03, MarkE <mark.engl... at rbccm.com> wrote:
> > No, sets aren't sequences, as they have no order. Same as dicts, which
> > aren't sequences either.
>
> Oops. I was under the misapprehension that they were sequences
I realise now that this is even explicitly documented:
http://docs.python.org/lib/typesseq.html
"There are six sequence types: strings, Unicode strings, lists,
tuples, buffers, and xrange objects."

> Is there a short Pythonic way to determine whether an object is
> iterable (iteratable ??) that I haven't thought of (getattr(obj,
> '__iter__') ?). Would operator.isIterable() be at all a useful
> addition ?
And here I probably meant container (although the url says sequence
when the article meant container, bit like me):
http://docs.python.org/ref/sequence-types.html
"Containers usually are sequences (such as lists or tuples) or
mappings (like dictionaries), but can represent other containers as
well"

So same question, but perhaps "isContainer()" rather than
"isIterable()"



More information about the Python-list mailing list