Equal sets with unequal print and str() representations

Ian Kelly ian.g.kelly at gmail.com
Sun Oct 16 21:17:57 EDT 2011


On Sun, Oct 16, 2011 at 5:52 PM, Ganesh Gopalakrishnan
<ganesh at cs.utah.edu> wrote:
> This probably is known, but a potential pitfall (was, for me) nevertheless.
> I suspect it is due to hash collisions between 's3' and 's13' in this case?
> It happens only rarely, depending on the contents of the set.

I'm not sure exactly which keys are colliding here, but in general the
iteration order of a set (or dict) depends not just on the contents,
but also on the order of insertion.  And of course the repr depends on
the iteration order -- anything consistent would require sorting,
which would be O(n log n) and is not even necessarily well-defined.



More information about the Python-list mailing list