0

Is there an algorithm in printing the contents of sets and dictionaries? What I mean is, let's say I have some set like this:

my_set = set({1,2.7,3,4.5,5}) 

If I print my_set, how do I know what order I'll get it in? I know it's using the same order over & over again for this particular set, but what if I don't know what my set is going to be? Is the order just random? Or is there an algorithm? How does this work for dictionaries, is it the same concept?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Daniel Cook
  • 1,856
  • 8
  • 23
  • 28
  • 1
    Sets use the same hashing algorithm, so the reasons for set ordering is the same as for dictionaries. – Martijn Pieters Nov 03 '13 at 01:33
  • 2
    Sets and dicts are unordered. They may be the same with the same data, but not always (depending on insertion order) – dawg Nov 03 '13 at 01:33
  • It's implementation-specific, and not something you should depend on. That's about all that can be said. – roippi Nov 03 '13 at 01:40

0 Answers0