How to check dict.has_key (k, x) with 2 variables

I created a dictionary with 2 keys that assign a single dictionary value, for example:

my_dict[x, y] = ...
my_dict[a, u] = ...

Now, how would I use the method has_key()for two key variables, x and y, such as:

if my_dict.has_key(x,y) == True:
    Do Something
else:
    Do something else

d is a matrix that uses the pdict values ​​that I call from the variable f and g, but all you need to know is that they are the names of the variables x, y, which are used as key values ​​in pdict.

+5
source share
2 answers

Since it has been dict.has_key()deprecated for a long time, the operator should be used instead in:

if (x, y) in my_dict:
    # whatever

, " ". , tuple , .

+10

:

d[1,2] = 3

. , , :

d.has_key((1,2))
+6

All Articles