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 tuples
On Nov 7, 11:54 am, Paul Rubin http://[EMAIL PROTECTED] 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 mostly
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 4 special keys in
On Nov 7, 3:05 pm, Paul Rubin http://[EMAIL PROTECTED] 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 would have the regular
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
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
--
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.
As I
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.
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.
As I have learnt, 0 and False both hash to the same value (same
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 (x,
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 distinct
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 this
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:
How do I make a
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 ones that
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 taken.
If
15 matches
Mail list logo