mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
xref
This commit is contained in:
@@ -205,7 +205,7 @@ AssertionError: Only for very large values of 2</samp></pre>
|
||||
<a><samp class=p>>>> </samp><kbd class=pp>tuple(ord(c) for c in unique_characters)</kbd> <span class=u>④</span></a>
|
||||
<samp class=pp>(69, 68, 77, 79, 78, 83, 82, 89)</samp></pre>
|
||||
<ol>
|
||||
<li>A generator expression is like an anonymous function that yields values. The expression itself looks like a list comprehension [FIXME have we introduced this yet?], but it’s wrapped in parentheses instead of square brackets.
|
||||
<li>A generator expression is like an anonymous function that yields values. The expression itself looks like a list comprehension [FIXME xref], but it’s wrapped in parentheses instead of square brackets.
|
||||
<li>The generator expression returns… an iterator.
|
||||
<li>Calling <code>next(<var>gen</var>)</code> returns the next value from the iterator.
|
||||
<li>If you like, you can iterate through all the possible values and return a tuple, list, or set, by passing the generator expression to <code>tuple()</code>, <code>list()</code>, or <code>set()</code>. In these cases, you don’t need an extra set of parentheses — just pass the “bare” expression <code>ord(c) for c in unique_characters</code> to the <code>tuple()</code> function, and Python figures out that it’s a generator expression.
|
||||
|
||||
Reference in New Issue
Block a user