classification
Title: Dict comprehensions
Type: Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: georg.brandl, gvanrossum, twouters (3)
Priority: normal Keywords: patch

Created on 2007-07-11 10:49 by twouters, last changed 2008-01-06 22:29 by admin.

Files
File name Uploaded Description Edit Remove
dictcomps.diff twouters, 2007-07-11 10:49
Messages (4)
msg52826 - (view) Author: Thomas Wouters (twouters) Date: 2007-07-11 10:49
Dict comprehensions, implemented somewhat like:

d = {}
for key, value in gen():
  d[key] = value

A version that passes the generator directly to dict() might be faster (although it would have to generate tuples instead of two separate items on the stack, which may negate the benefit of doing the actual dict assignment in C) -- and of course the danger of passing the generator to a local or global 'dict' variable instead of the builtin 'dict'.

Includes tests, but not compiler-package or documentation changes (yet).
msg52827 - (view) Author: Georg Brandl (georg.brandl) Date: 2007-07-11 11:46
I tested the patch shallowly, works fine. I think this is a good feature to have, even if only for completeness.
The tests don't seem to be included.

compiler package changes won't be needed, as it has been removed from Py3k,
but probably changes to parsermodule.c.
msg52828 - (view) Author: Guido van Rossum (gvanrossum) Date: 2007-07-11 12:12
Check it in!  (This one I meant, not the other one which was my mistake.)
msg52829 - (view) Author: Thomas Wouters (twouters) Date: 2007-07-11 12:25
Verbally accepted by Guido (honest), and checked in.
History
Date User Action Args
2008-01-06 22:29:45adminsetkeywords: - py3k
versions: + Python 3.0
2007-07-11 10:49:17twouterscreate