Newcomer to Python tutorial question

Chris Rebert clp2 at rebertia.com
Thu May 7 14:40:57 EDT 2009


On Thu, May 7, 2009 at 11:35 AM, Alan Cameron <alan.cameron at iname.com>
wrote> I am not sure of this is the right place to ask a question
about the
> tutorial
>
> http://docs.python.org/3.0/tutorial/datastructures.html#sets
>
> why is the printed result of
>
>>>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>>> print(basket)
> {'orange', 'banana', 'pear', 'apple'}
>
> in the sequence given?

Because it's *not a sequence* at all, it's a set. Sets are unordered
and contain no duplicate items, hence why the output ordering is
arbitrary and only the unique subset of original elements is present.

Further info: http://docs.python.org/3.0/library/stdtypes.html#set-types-set-frozenset

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list