False and 0 in the same dictionary

John Machin sjmachin at lexicon.net
Fri Nov 7 01:17:22 EST 2008


On Nov 7, 3:05 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> John Machin <sjmac... 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]

Possibly you meant:

key = (x, type(x))
if key in dict1: return dict1[key]

>        return dict2(x)
>
> so dict1 would contain tuples as keys, but just a few of them.




More information about the Python-list mailing list