On 28 September 2010 23:58, Alex Hall wrote:
> Hi all, yet again:
> I have a dictionary that will look something like:
> d={
> (1,2):"a",
> (3,4):"b"
> }
>
> How can I say:
> if (1,2) in d: print d[(1,2)]
This will work fine.
> This is false
Not it is not..
>>> d = {(1,2):"a",(3,4):"b"}
>>> (
On Wed, 29 Sep 2010 07:58:28 am Alex Hall wrote:
> Hi all, yet again:
> I have a dictionary that will look something like:
> d={
> (1,2):"a",
> (3,4):"b"
> }
>
> How can I say:
> if (1,2) in d: print d[(1,2)]
Exactly like that:
>>> d = {(1,2): 'a', (3,4): 'b'}
>>> if (1,2) in d: print d[(1,2)]
On 28-Sep-10 14:58, Alex Hall wrote:
Hi all, yet again:
I have a dictionary that will look something like:
d={
(1,2):"a",
(3,4):"b"
}
How can I say:
if (1,2) in d: print d[(1,2)]
Did you try this? It looks fine to me as it is.
(1,2) is an immutable value (a tuple), so it is able to be use
On Tue, Sep 28, 2010 at 4:58 PM, Alex Hall wrote:
> Hi all, yet again:
> I have a dictionary that will look something like:
> d={
> (1,2):"a",
> (3,4):"b"
> }
>
> How can I say:
> if (1,2) in d: print d[(1,2)]
> This is false, so I expect to have to use d.keys, but I am not quite sure
> how.
>
Hi all, yet again:
I have a dictionary that will look something like:
d={
(1,2):"a",
(3,4):"b"
}
How can I say:
if (1,2) in d: print d[(1,2)]
This is false, so I expect to have to use d.keys, but I am not quite sure how.
I will be using this in a loop, and I have to know if there is a key
in the