Equal sets with unequal print and str() representations

  • Thread starter Ganesh Gopalakrishnan
  • Start date
G

Ganesh Gopalakrishnan

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.
S1
{'s8', 's13', 's2', 's0', 's7', 's6', 's4', 's3', 's14'}S2
{'s8', 's3', 's2', 's0', 's7', 's6', 's4', 's13', 's14'}
S1==S2
True
str(S1)
"{'s8', 's13', 's2', 's0', 's7', 's6', 's4', 's3', 's14'}"str(S2)
"{'s8', 's3', 's2', 's0', 's7', 's6', 's4', 's13', 's14'}"False
 
G

Ganesh Gopalakrishnan

Thanks to all who replied - also to Ben. I had foolishly assumed that
the same set exhibits the same rep on at least one platform. Like any
bug, the falsity of my assumption took months to expose - till then,
things had worked fine. Needless to say I'm new to Python. (The double
printing is because I tend to work within an Emacs inferior shell.)

Cheers,

Ganesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top