Newcomer to Python tutorial question

Peter Otten __peter__ at
Thu May 7 20:58:49 CEST 2009

Alan Cameron wrote:

> I am not sure of this is the right place to ask a question about the
> tutorial
> why is the printed result of
>>>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>>> print(basket)
> {'orange', 'banana', 'pear', 'apple'}
> in the sequence given?

As already said by others, the order of items in a set is not part of the 
concept of a set. 

You can even have sets with equal contents that display differently:

Python 3.0.1+ (r301:69556, Apr 15 2009, 17:25:52)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = {'orange', 'banana', 'apple', 'orange', 'pear', 'apple'}
>>> b = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>> a == b
>>> repr(a) == repr(b)
>>> a
{'orange', 'pear', 'apple', 'banana'}
>>> b
{'orange', 'pear', 'banana', 'apple'}


More information about the Python-list mailing list