@@ -154,6 +154,8 @@ the queue, use :meth:`pop` with ``0`` as the index. For example::
154154 ['Michael', 'Terry', 'Graham']
155155
156156
157+ .. _tut-listcomps :
158+
157159List Comprehensions
158160-------------------
159161
@@ -401,7 +403,7 @@ Here is a brief demonstration::
401403 >>> a ^ b # letters in a or b but not both
402404 {'r', 'd', 'b', 'm', 'z', 'l'}
403405
404- Like for lists, there is a set comprehension syntax::
406+ Like :ref: ` for lists < tut-listcomps >` , there is a set comprehension syntax::
405407
406408 >>> a = {x for x in 'abracadabra' if x not in 'abc'}
407409 >>> a
@@ -438,9 +440,9 @@ value associated with that key is forgotten. It is an error to extract a value
438440using a non-existent key.
439441
440442Performing ``list(d.keys()) `` on a dictionary returns a list of all the keys
441- used in the dictionary, in arbitrary order (if you want it sorted, just apply
442- the :meth: ` sorted ` function instead). To check whether a single key is
443- in the dictionary, use the :keyword: `in ` keyword.
443+ used in the dictionary, in arbitrary order (if you want it sorted, just use
444+ `` sorted(d.keys()) `` instead). [ 1 ]_ To check whether a single key is in the
445+ dictionary, use the :keyword: `in ` keyword.
444446
445447Here is a small example using a dictionary::
446448
@@ -463,9 +465,8 @@ Here is a small example using a dictionary::
463465 >>> 'jack' not in tel
464466 False
465467
466- The :func: `dict ` constructor builds dictionaries directly from lists of
467- key-value pairs stored as tuples. When the pairs form a pattern, list
468- comprehensions can compactly specify the key-value list. ::
468+ The :func: `dict ` constructor builds dictionaries directly from sequences of
469+ key-value pairs stored as tuples. ::
469470
470471 >>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
471472 {'sape': 4139, 'jack': 4098, 'guido': 4127}
@@ -483,7 +484,6 @@ keyword arguments::
483484 {'sape': 4139, 'jack': 4098, 'guido': 4127}
484485
485486
486- .. XXX Find out the right way to do these DUBOIS
487487.. _tut-loopidioms :
488488
489489Looping Techniques
@@ -604,9 +604,9 @@ sequence is exhausted. If two items to be compared are themselves sequences of
604604the same type, the lexicographical comparison is carried out recursively. If
605605all items of two sequences compare equal, the sequences are considered equal.
606606If one sequence is an initial sub-sequence of the other, the shorter sequence is
607- the smaller (lesser) one. Lexicographical ordering for strings uses the ASCII
608- ordering for individual characters. Some examples of comparisons between
609- sequences of the same type::
607+ the smaller (lesser) one. Lexicographical ordering for strings uses the Unicode
608+ codepoint number to order individual characters. Some examples of comparisons
609+ between sequences of the same type::
610610
611611 (1, 2, 3) < (1, 2, 4)
612612 [1, 2, 3] < [1, 2, 4]
@@ -621,3 +621,10 @@ provided that the objects have appropriate comparison methods. For example,
621621mixed numeric types are compared according to their numeric value, so 0 equals
6226220.0, etc. Otherwise, rather than providing an arbitrary ordering, the
623623interpreter will raise a :exc: `TypeError ` exception.
624+
625+
626+ .. rubric :: Footnotes
627+
628+ .. [1 ] Calling ``d.keys() `` will return a :dfn: `dictionary view ` object. It
629+ supports operations like membership test and iteration, but its contents
630+ are not independent of the original dictionary -- it is only a *view *.
0 commit comments