Dictionaries and incrementing keys

Steve Crook steve at mixmin.net
Tue Jun 14 08:53:11 EDT 2011


On Tue, 14 Jun 2011 05:37:45 -0700 (PDT), AlienBaby wrote in
Message-Id: <078c5e9a-8fad-4d4c-b081-f69d0f57593d at v11g2000prk.googlegroups.com>:

> How do those methods compare to the one I normally use;
>
> try:
>  dict[key]+=1
> except:
>  dict[key]=1

This is a lot slower in percentage terms.  You should also qualify the
exception: except KeyError



More information about the Python-list mailing list