Re: Fast Dictionary Access

2009-06-29 Thread Paul Rubin
Duncan Booth duncan.bo...@invalid.invalid writes: The suggested alternative: value = data.get(key, None) also has two dictionary lookups:... dg = data.get ... (inside loop): value = dg(key,None) -- http://mail.python.org/mailman/listinfo/python-list

Re: Fast Dictionary Access

2009-06-28 Thread Ben Finney
Steven D'Aprano st...@remove-this-cybersource.com.au writes: On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote: [...] Raymond Raymond, does Rachel know you're using her gmail account? It's a good thing names are being used here, rather than just initials. -- \“No one ever

Re: Fast Dictionary Access

2009-06-28 Thread Carl Banks
On Jun 27, 4:40 am, Duncan Booth duncan.bo...@invalid.invalid wrote: Thomas Lehmann iris-und-thomas-lehm...@t-online.de wrote: Hi! In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new

Re: Fast Dictionary Access

2009-06-28 Thread Steven D'Aprano
On Sun, 28 Jun 2009 02:57:50 -0700, Carl Banks wrote: So it's not valid in general to equate the two lookups. Unless you know that your dict keys are going to be really fast like interned strings it makes sense to minimize dict lookups. Or to stop making assumptions about what's fast and

Fast Dictionary Access

2009-06-27 Thread Thomas Lehmann
Hi! In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is to have one search only. code if data.has_key(key): value = data[key] /code But this does

Re: Fast Dictionary Access

2009-06-27 Thread Chris Rebert
On Sat, Jun 27, 2009 at 2:47 AM, Thomas Lehmanniris-und-thomas-lehm...@t-online.de wrote: Hi! In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is

Re: Fast Dictionary Access

2009-06-27 Thread Paul Rubin
Thomas Lehmann iris-und-thomas-lehm...@t-online.de writes: code if data.has_key(key): value = data[key] /code But this does mean (does it?) that the dictionary is searched two times! If so, can somebody show me how to do this in one step? value = data.get(key, None) sets value to

Re: Fast Dictionary Access

2009-06-27 Thread Duncan Booth
Thomas Lehmann iris-und-thomas-lehm...@t-online.de wrote: Hi! In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is to have one search only.

Re: Fast Dictionary Access

2009-06-27 Thread Rachel P
[Thomas Lehmann] In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is to have one search only. code if  data.has_key(key):    value = data[key]

Re: Fast Dictionary Access

2009-06-27 Thread Scott David Daniels
Thomas Lehmann wrote: In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is to have one search only. code if data.has_key(key): value = data[key]

Re: Fast Dictionary Access

2009-06-27 Thread Steven D'Aprano
On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote: [...] Raymond Raymond, does Rachel know you're using her gmail account? *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list