[Tutor] unordered and ordered defaultdict(set)

Larry Riedel Larry at riedel.org
Fri Oct 31 00:30:16 CET 2008

> Unless my eyes are squiffy the 2nd dictionary of sets
> appears ordered.  I've run it with other numbers > 25
> and continue to get ordered sets but anything < 25
> results in unordered sets.  A feature or a bug?

No, not a feature or a bug... it would be a bug to assume
the elements will be in order, or to assume the elements
will not be in order.  It is a happenstance if they are.
Maybe for that implementation of the Python runtime that
happenstance is consistent, but on another it may not be.

My guess (totally a guess) would be for small sets it is
expected to be faster to use an array with a linear search
than a tree with fewer operations per search, so the
implementation starts with an array until the set gets
big enough to justify using a tree, then it switches over.


More information about the Tutor mailing list