diff --git a/pep-0572.rst b/pep-0572.rst index 6e5fcd6ae..108f5687a 100644 --- a/pep-0572.rst +++ b/pep-0572.rst @@ -163,6 +163,10 @@ These list comprehensions are all approximately equivalent:: yield [y, x/y] stuff = list(g()) + # Using a mutable cache object (various forms possible) + c = {} + stuff = [[c.update(y=f(x)) or c['y'], x/c['y']] for x in range(5)] + # Using a statement-local name stuff = [[(f(x) as y), x/y] for x in range(5)]