>>> x = {"a","b","c","d","e"}
>>> print x
set(['a', 'c', 'b', 'e', 'd'])
Who can help to explain why the sequence of set elements changed after it is printed out?
-- Update: Thanks guys!
Yes, set is a set of elements, there is no order for "set". but every time you print, the output is the same. Please help explain why the set {"a","b","c","d","e"} was saved as ['a', 'c', 'b', 'e', 'd'] by python, in what kind of order? it seems not in the sequence of ASCII of characters.
-- Update: Paul Rooney's answer is the root cause I want to know. The order of set output relates to the hash of each element in the set which is explained in the official document. Thanks!
The order is dictated by the hashes of the values, the size of the underlying hash table and the number of hash collisions that occurred. See here --Paul Rooney