Re: Way for see if dict has a key



"André" wrote:

Perhaps Bruno meant this:

try:
... my_dict[key] ...
except:
...

when we expect that the key will most often be in my_dict so that
exception will be raised rarely, otherwise use

on my machine, "key in dict" is about twice as fast as the full try/getitem con-
struct when the key is present in the dict, so that's not a very good optimization.

now, if the OP had been interested in the associated value, things might have
been a bit different.

</F>



.



Relevant Pages

  • [PATCH] sort exception tables
    ... This patch arranges for the exception tables to be sorted on most ... +void sort_extable(struct exception_table_entry *start, ... search_extable(const struct exception_table_entry *first, ... -/* Simple binary search */ ...
    (Linux-Kernel)
  • Re: Check if Function Exists
    ... a block would throw an exception without executing this block to begin with. ... The catch block's identifier is then bound to that new object. ... Because such optimization would be unobservable, it could not be shown to be non-complian. ... throw atom; ...
    (comp.lang.javascript)
  • RE: Strange behavior with dynamic code compilation and VS.NET debu
    ... I think someone else suggested that it was optimization related; ... "Mike Miller" wrote: ... > so when I compile with debugging information I get different behavior then ... >> And you'll get the usual exception information when the program aborts. ...
    (microsoft.public.dotnet.framework)
  • Re: N1298 - try/finally for C
    ... struct Info; ... exception type semantics for C have to be much simpler. ... The compiler allocates the 'info' object on the local ... block stack, then copied the contents of the object when ...
    (comp.std.c)
  • Re: N1298 - try/finally for C
    ... // throws a struct object ... Ian Collins wrote: ... for cleaning up the stack appropriately during exception ... block stack, then copied the contents of the object when ...
    (comp.std.c)