basic question, sorry

Will Ware wware at world.std.com
Mon Aug 21 08:56:11 EDT 2000


I wrote:
> if n in dict.keys():
>         do stuff

Just van Rossum (just at letterror.com) wrote:
> No!! That's a linear search through the keys list. Additionally, this
> key list must be created first. So this is *always* slower.

Yeah, that occurred to me about a half-second after I posted that
response. in...keys() would work but would impose a huge performance
lose. (I try to think a little more carefully when writing code
that I plan to actually run.) The try/except thing looks interesting,
I'll have to study the later comment that it's substantially faster
than has_key().
-- 
# - - - - - - - - - - - - - - - - - - - - - - - -
# Resistance is futile. Capacitance is efficacious.
# Will Ware	email:    wware @ world.std.com



More information about the Python-list mailing list