Alan Cameron wrote:

why is the printed result of

basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
print(basket)
{'orange', 'banana', 'pear', 'apple'}

in the sequence given?

It appears that I used a reserved term when I used 'sequence'.

No and Sort-of.

No: We often use it in the normal English sense of ordered items, as I and I think others assume you did. Your question is quite legitimate, and the answer, as indicated, is how an implementation interacts with the sequence of additions.

Sort-of: The library manual section of Sequence Types lists the sequence operations common to all or most built-in Python sequence classes. But it does not explicitly define sequence. Ranges, which are iterables that directly support only indexing and len(), are called sequences. Dicts, which are iterables that support len() but are usually not indexed by integers, are not. So that suggests a minimal definition of sequence, but all the other sequence classes support much more that is typically assumed.

Keywords are reserved terms in the language such as 'if' and 'None' that are specially recognized by the parser and which affect compilation. Identifiers of the form '__x...y__' are reserved names. Non-terminal terms in the grammar are reserved terms, in a sense, within the reference manual, but 'expression_list', not 'sequence', is used for comma-separated sequences of expressions in code. The comma-separated sequence of items in a function call is separately defined as an 'argument_list' because 'keyword_item's like 'a=b' and '*' and '**' are not expressions and because there are some order restrictions on argument items.

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to