and [True,True] --> [True, True]?????

Steven D'Aprano steve at
Fri Apr 24 13:17:26 CEST 2009

On Fri, 24 Apr 2009 03:22:50 -0700, Paul Rubin wrote:

> Steven D'Aprano <steve at> writes:
>> len() works on dicts and sets, and they're not sequences.
> Of course dicts and sets are sequences.

Dicts and sets are explicitly described as "other containers":

Note that addition is included in the table of sequence operations, but 
neither dicts nor sets support it:

>>> {} + {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'

Nor do they support slicing.

> But there are also sequences on which len doesn't work.
> You could use:  sum(1 for x in seq)
> Of course iterating through seq may have undesired side effects.

It's also not guaranteed to terminate.

Well, technically no user-defined function is guaranteed to terminate, 
but you know what I mean :)


More information about the Python-list mailing list