Re: Fast Dictionary Access

2009-06-29 Thread Paul Rubin
Duncan Booth 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 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 w

Re: Fast Dictionary Access

2009-06-28 Thread Carl Banks
On Jun 27, 4:40 am, Duncan Booth wrote: > Thomas Lehmann 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 > > o

Re: Fast Dictionary Access

2009-06-28 Thread Ben Finney
Steven D'Aprano 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 went broke underestimating the

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

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. if data.has_key(key): value = data[key] But

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. > > > if  data.has_key(key): >    value = data[key

Re: Fast Dictionary Access

2009-06-27 Thread Duncan Booth
Thomas Lehmann 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. > > > if data.has_key(key): >

Re: Fast Dictionary Access

2009-06-27 Thread Paul Rubin
Thomas Lehmann writes: > > if data.has_key(key): >value = data[key] > > > 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 None if the key is not in the dictiona

Re: Fast Dictionary Access

2009-06-27 Thread Chris Rebert
On Sat, Jun 27, 2009 at 2:47 AM, Thomas Lehmann 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. > >

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. if data.has_key(key): value = data[key] But this does mean (doe