Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Peter Hansen
Dave Merrill 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. You're probably getting the error shown. Try the change in the line following it instead. Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]

Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Jean Brouwers
The correct syntax is: dict([(key, row[key]) for key in cols]) i.e. the list must be enclosed in [...]. /Jean Brouwers In article <[EMAIL PROTECTED]>, Dave Merrill <[EMAIL PROTECTED]> wrote: > "anton muhin" wrote: > > Stefan Behnel wrote: > > > > > > > > > shark schrieb: > > > > > >> ro

Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Simon Brunning
On Wed, 1 Dec 2004 10:23:28 -0500, Dave Merrill <[EMAIL PROTECTED]> 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 wo

Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Dave Merrill
"anton muhin" wrote: > Stefan Behnel wrote: > > > > > > shark schrieb: > > > >> row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", > >> "state" : > >> "Alaska"} > >> cols = ("city", "state") > >> > >> Is there a best-practices way to ask for an object containing only the > >> keys > >

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Bengt Richter
On Tue, 30 Nov 2004 21:54:46 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: [...] > >If there's an overall why for doing it at all, why not just iterate through >keys of interest? I.e., (untested) > > dict( (key, row[key]) for key in cols ) > Sorry Anton, I didn't see your post. Newsfeed delays seem

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Bengt Richter
On Tue, 30 Nov 2004 15:20:19 +0100, Stefan Behnel <[EMAIL PROTECTED]> wrote: > > >shark schrieb: >> row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : >> "Alaska"} >> cols = ("city", "state") >> >> Is there a best-practices way to ask for an object containing only the keys

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread anton muhin
Stefan Behnel wrote: shark schrieb: row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : "Alaska"} cols = ("city", "state") Is there a best-practices way to ask for an object containing only the keys named in cols out of row? In other words, to get this: {"city" : "Hoboken

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Stefan Behnel
shark schrieb: row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : "Alaska"} cols = ("city", "state") Is there a best-practices way to ask for an object containing only the keys named in cols out of row? In other words, to get this: {"city" : "Hoboken", "state" : "Alaska"} U

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "shark" <[EMAIL PROTECTED]> wrote: > row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : > "Alaska"} > cols = ("city", "state") > > Is there a best-practices way to ask for an object containing only the keys > named in cols out of row? In ot

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Leif K-Brooks
shark wrote: row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : "Alaska"} cols = ("city", "state") Is there a best-practices way to ask for an object containing only the keys named in cols out of row? In other words, to get this: {"city" : "Hoboken", "state" : "Alaska"} Why

Syntax for extracting multiple items from a dictionary

2004-11-30 Thread shark
row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : "Alaska"} cols = ("city", "state") Is there a best-practices way to ask for an object containing only the keys named in cols out of row? In other words, to get this: {"city" : "Hoboken", "state" : "Alaska"} Thanks, shark