In order to create a function that will be neccesary to create another one later I am working with dict and keys. In this way I have been searching some information about how they work. But when I have to use dict and if statements I usually get stuck.
I am workin in a function that return the number of values in dict that are also keys in dict. My fisrt thought was to use a for loop but I get stuck in the if statement code. It seems be wrong but I don't know what could be. I have deduced that I must use an in operator and the variables k and d, and also an indexing but I don't know if I am using them properly. Any help will be useful. Thanks in advance
This is my current progress:
def count_values_that_are_keys(d):
'''(dict) -> int
Return the number of values in d that are also keys in d.
>>> count_values_that_are_keys({1: 2, 2: 3, 3: 3})
3
>>> count_values_that_are_keys({1: 1})
1
>>> count_values_that_are_keys({1: 2, 2: 3, 3: 0})
2
>>> count_values_that_are_keys({1: 2})
0
'''
result = 0
for k in d:
if [d in [k]]: # This part it seems wrong cause I don't get what I expect
result = result + 1
return result