False and 0 in the same dictionary

Paul Rubin http
Fri Nov 7 05:05:38 CET 2008


John Machin <sjmachin at lexicon.net> writes:
> > You could use a second dict for the other type:
> >
> >   def lookup(x):
> >     if x in dict1: return dict1[x]
> >     return dict2[x]
> >
> > dict1 would have the 4 special keys and dict2 would have the regular
> > keys.
> 
> 
> Ummm how do you get "the 4 special keys" in dict1?

oops, adjoin the type

     def lookup(x):
       if (x,type(x)) in dict1: return dict1[x]
       return dict2(x)

so dict1 would contain tuples as keys, but just a few of them.



More information about the Python-list mailing list