This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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
Priority: normal Keywords: patch

Created on 2007-07-11 10:49 by twouters, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
dictcomps.diff twouters, 2007-07-11 10:49
Messages (4)
msg52826 - (view) Author: Thomas Wouters (twouters) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2007-07-11 12:25
Verbally accepted by Guido (honest), and checked in.
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45167
2008-01-06 22:29:45adminsetkeywords: - py3k
versions: + Python 3.0
2007-07-11 10:49:17twouterscreate