ACCEPTED: PEP 285
Delaney, Timothy
tdelaney at avaya.com
Thu Apr 4 20:34:39 EST 2002
> From: James Logajan [mailto:JamesL at Lugoj.com]
>
> Eri Ma Franci <max at alcyone.com> wrote:
> > Could you find something better to complain about?
>
> Then I'd like to complain that neither you nor Guid va Rossu
> addressed the
> question I asked in my previous message concerning bools as
> keys. If a bool
> is to be treated as an int sometimes and sometimes not, I
> don't recall
> seeing anything about whether it will be treated as an int as
> a dictionary
> key. If I do:
>
> x = ["is", "are"]
> y = {0: "", 1:"s"}
>
> for n in range(3):
> print "There %s %d item%s." % (x[n <> 1], n, y[n <> 1])
This has been addressed *many* times in these threads. If you have failed to
read them, that is your problem.
One last time.
True compares equal to 1. False compares equal to 0. Therefore, in a
dictionary, True and 1 are synonymous as keys, and False and 0 are
synonymous as keys. So, the following code:
d = {}
d[0] = 'Hello'
d[1] = 'World'
d[True] = 'T'
d[False] = 'F'
print len(d)
print d[1]
print d[True]
print d[False]
print d[0]
will print:
2
T
T
F
F
If that doesn't answer your question, I have no idea what will. There is no
ambiguity.
A bool *is an* int according to PEP 285, which has been accepted.
Tim Delaney
More information about the Python-list
mailing list