From c5b251e75689dde128fc11eab5ed3a060aa1c282 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Sat, 24 Mar 2018 20:25:27 +1100 Subject: [PATCH] PEP 572: Add another alternate spelling --- pep-0572.rst | 4 ++++ 1 file changed, 4 insertions(+) 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)]