Syntax for extracting multiple items from a dictionary

Simon Brunning simon.brunning at gmail.com
Wed Dec 1 10:36:08 EST 2004


On Wed, 1 Dec 2004 10:23:28 -0500, Dave Merrill <dmerrillq at usaq.netq> wrote:
> "anton muhin" wrote:
> > Or dict((key, row[key]) for key in cols).
> 
> I'm on Py 2.3.3, and neither of these appear to work. Can someone confirm? I
> can't see anything in the 2.4 release notes that point to where this would
> have changed.

They use generator expressions, which were introduced by Python 2.4.
See <http://www.python.org/dev/doc/devel/whatsnew/node4.html>.

-- 
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list