Re: False and 0 in the same dictionary

2008-11-06 Thread John Machin
On Nov 7, 3:05 pm, Paul Rubin wrote: > John Machin <[EMAIL PROTECTED]> 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 wou

Re: False and 0 in the same dictionary

2008-11-06 Thread Paul Rubin
John Machin <[EMAIL PROTECTED]> 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

Re: False and 0 in the same dictionary

2008-11-06 Thread John Machin
On Nov 7, 11:54 am, Paul Rubin wrote: > Prateek <[EMAIL PROTECTED]> writes: > > > How about using (x, type(x)) as the key instead of just x? > > Yup. I thought of that. Although it seems kinda unpythonic to do so. > > Especially since the dictionary is basically a cache m

Re: False and 0 in the same dictionary

2008-11-06 Thread Paul Rubin
Prateek <[EMAIL PROTECTED]> writes: > > How about using (x, type(x)) as the key instead of just x? > Yup. I thought of that. Although it seems kinda unpythonic to do so. > Especially since the dictionary is basically a cache mostly containing > strings. Adding all the memory overhead for the extra

Re: False and 0 in the same dictionary

2008-11-05 Thread Carl Banks
On Nov 4, 3:48 pm, Prateek <[EMAIL PROTECTED]> wrote: > I've been using Python for a while (4 years) so I feel like a moron > writing this post because I think I should know the answer to this > question: > > How do I make a dictionary which has distinct key-value pairs for 0, > False, 1 and True.

Re: False and 0 in the same dictionary

2008-11-05 Thread Marc 'BlackJack' Rintsch
On Wed, 05 Nov 2008 04:22:32 -0800, bearophileHUGS wrote: > In Python if bools become distinct from integers you have to rewrite > things like: > sum(el == val for el in iterable) > as: > sum(1 for el in iterable if el == val) I would expect that you can still "cast" `bool`\s to `int`\s then. S

Re: False and 0 in the same dictionary

2008-11-05 Thread bearophileHUGS
Prateek: > How do I make a dictionary which has distinct key-value pairs for 0, > False, 1 and True. Why do you have to do that? What's the problem you have to solve? Maybe (probably) there are better or more clean alternative solutions. Bye, bearophile -- http://mail.python.org/mailman/listinfo/

Re: False and 0 in the same dictionary

2008-11-05 Thread bearophileHUGS
Ben Finney: > Is there a later PEP that I've missed which > finally makes ‘bool’ a type independent from ‘int’? In a tidy language like an ObjectPascal or Java bools and integers are different types. In Python if bools become distinct from integers you have to rewrite things like: sum(el == val f

Re: False and 0 in the same dictionary

2008-11-04 Thread Hendrik van Rooyen
"Prateek" <[EMAIL PROTECTED]> wrote: > >>> b = {0:'xyz', False:'abc'} > >>> b > {0: 'abc'} # Am I the only one who thinks this is weird? No. This was discussed before on this list, and that discussion referenced (if I recall correctly) the discussion on python-dev at the time the decision was

Re: False and 0 in the same dictionary

2008-11-04 Thread Ben Finney
Prateek <[EMAIL PROTECTED]> writes: > >>> b = {0:'xyz', False:'abc'} > >>> b > {0: 'abc'} # Am I the only one who thinks this is weird? You're not the only one; I consider this a wart in Python. False and True should be discrete values that don't compare equal with any other value, not even one

Re: False and 0 in the same dictionary

2008-11-04 Thread Arnaud Delobelle
Prateek <[EMAIL PROTECTED]> writes: > On Nov 5, 1:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote: >> Prateek <[EMAIL PROTECTED]> wrote: >> > I've been using Python for a while (4 years) so I feel like a moron >> > writing this post because I think I should know the answer to this >> > question: >>

Re: False and 0 in the same dictionary

2008-11-04 Thread bdbull
On Nov 4, 4:21 pm, Prateek <[EMAIL PROTECTED]> wrote: > On Nov 5, 1:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > > > Prateek <[EMAIL PROTECTED]> wrote: > > > I've been using Python for a while (4 years) so I feel like a moron > > > writing this post because I think I should know the answer to t

Re: False and 0 in the same dictionary

2008-11-04 Thread Prateek
On Nov 5, 1:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > Prateek <[EMAIL PROTECTED]> wrote: > > I've been using Python for a while (4 years) so I feel like a moron > > writing this post because I think I should know the answer to this > > question: > > > How do I make a dictionary which has dis

Re: False and 0 in the same dictionary

2008-11-04 Thread Duncan Booth
Prateek <[EMAIL PROTECTED]> wrote: > I've been using Python for a while (4 years) so I feel like a moron > writing this post because I think I should know the answer to this > question: > > How do I make a dictionary which has distinct key-value pairs for 0, > False, 1 and True. How about using