Re: Newcomer to Python tutorial question
Terry Reedy tjre...@udel.edu wrote in message news:mailman.5248.1241732704.11746.python-l...@python.org... 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 Thanks for the explanation. In particular reference to the tutorial section http://docs.python.org/3.0/tutorial/datastructures.html#nested-list-comprehensions There is a word which is ambiguous, at least to me. Perhaps you can explain the use of the word 'comprehensions'. Comprehension I understand Comprehensions I don't. Is there a glossary of terms somewhere? -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list
Newcomer to Python tutorial question
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? -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Alan Cameron alan.came...@iname.com wrote in message news:hrfml.50224$tb.4...@newsfe07.ams2... 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? Thanks to all who replied. I assume therefore that the order in which the items of the set are printed could vary each time it is printed? -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Chris Rebert c...@rebertia.com wrote in message news:mailman.5238.1241723354.11746.python-l...@python.org... On Thu, May 7, 2009 at 11:58 AM, Alan Cameron alan.came...@iname.com wrote: Alan Cameron alan.came...@iname.com wrote in message news:hrfml.50224$tb.4...@newsfe07.ams2... 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? Thanks to all who replied. I assume therefore that the order in which the items of the set are printed could vary each time it is printed? Due to the underlying dict-based implementation, the order will stay the same until you modify the set (i.e. add or remove an element), at which point it may change; it's basically the same behavior as with printing a dict. So this will always print the same thing twice: print basket print basket Whereas this might not: print basket #modify the set basket.discard(banana) basket.add(banana) print basket Cheers, Chris Thanks Chris, It appears that I used a reserved term when I used 'sequence'. I just had not reached that far in the tutorial. I have many years of programming (roughly 50) and want to learn new languages. I find tutorials always fraught with problems due to the knowledge of the writer exceeding the knowledge of the reader and using terms and examples not yet covered in the tutorial thus far. I am persevering with my initial foray into Python. -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list